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 @@ +Larabie Fonts "read me" file, license and FAQ

LARABIE FONTS “README.TXT”

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

LARABIE FONTS FREQUENTLY ASKED QUESTIONS

  • Q: How do use these fonts in my favourite software?
  • A: In Windows, you take the fonts out of the ZIP archive and place them in your fonts folder which can be found in your Control Panel. The next time you run your software, the font will be available. For example: If you install a new font, the next time you run Microsoft Word, that font will be available in the menu under Format / Font. For anything more complicated, or Mac installation, visit www.larabiefonts.com/help.html
  • Q: How can I use this font in AOL Instant Messenger, MSN Messenger, Outlook, Outlook Express, Euodora or any other email software?
  • A: At the time of this writing (Feb 2004) you can’t. After installing one of my fonts, you may be able to select it in the above applications but the person at the other end won’t see that same thing unless they have the font installed. If you really want to use my fonts in these applications, make sure the people at the other end have the same fonts installed.
  • Q: How can I use these fonts on a web page?
  • A: If you’re creating a web page using Flash, it’s easy. Consult your Flash manual. If you’re using Acrobat, make sure the font embedding settings are turned on. Consult your Acrobat manual. For anything else there are limitations: If you want to use one of my fonts as your main, text font you’re pretty much out of luck unless you explore a font embedding tool such as WEFT but I don’t recommend it. To use my fonts as headings or titles, use image creation software such as The Gimp, Photoshop, Paint Shop Pro, Pixia etc. Save the images as GIF files and place them on your web page. There’s a lot more to it than can be explained here but there are countless books available on web page design.
  • Q: How can I make these fonts bigger?
  • A: All my fonts are infinitely scalable; the limitations are in your software. A common problem is scaling fonts in Microsoft Word. If you choose Format / Font you can type in any number you like under “size”.
  • Q: Are these fonts really free?
  • A: Yes they are. Some fonts such as Neuropol have expanded font families available for sale at www.typodermic.com but the version you downloaded at Larabie Fonts is free.
  • Q: Your licence agreement states that the fonts can’t be altered. Does that mean I can’t mess around with your fonts in Photoshop/Illustrator/Publisher etc?
  • A: Those license restrictions refer to altering the actual fonts themselves, not what you make with them. As long as you don’t alter the font files in font creation software such as FontLab or Fontographer you’re free to create anything you like with them.
  • Q: Can I use your fonts in a logo?
  • A: Yes. But check with a lawyer if you’re not sure. It’s okay with me if you use it but do so at your own risk.
  • Q: Can you make a custom font for me?
  • A: Possibly. Check typodermic.com/custom.html for details. Keep in mind that making fonts is my full-time job so no freebies.
  • Q: I want to sell rubber stamp alphabets, alphabet punches or stencil alphabets using your font designs.
  • A: Contact me first at www.larabiefonts.com/email.html.
  • Q: My software won’t let me embed one of your fonts.
  • A: You may have an old version of one of my fonts. Uninstall it and install a current version on Larabie Fonts.
  • Q: Can you help me find a font?
  • A: I really don’t have the time but if you send a donation, I can give it a try. If not. post your question on my font forum: www.larabiefonts.com/info.html.

LARABIE FONTS END-USER LICENSE AGREEMENT FOR SOFTWARE PRODUCTS

SOFTWARE PRODUCT LICENSE

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.

1. GRANT OF LICENSE. This document grants you the following rights:

- 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.

2. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS.

- 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.

3. MISCELLANEOUS

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 -100) + { + emitVertex( Pos : POSITION, Vel : TEXCOORD2, Timer : TEXCOORD0, Type : TEXCOORD1); + } +} + +// +// Sample a random direction from our random texture +// +float3 RandomDir(float fOffset, float globalTime, sampler1D randomTex) +{ + float tCoord = (globalTime + fOffset) / 300.0; + return tex1D(randomTex, tCoord).rgb; +} + +// +// Launcher type particle handler +// +void GSLauncherHandler( float3 Pos, float3 Vel, float Timer, float Type, + float elapsedTime, + float globalTime, + sampler1D randomTex, + float secondsPerFirework) +{ + if(Timer <= 0) + { + float3 vRandom = normalize( RandomDir( Type, globalTime, randomTex) ); + //Give it more of an up bias + vRandom = normalize(vRandom + float3(0,2.5,0)); + + //time to emit a new SHELL + float3 outputPos = Pos + Vel*elapsedTime; + float3 outputVel = Vel + vRandom*35.0; + float outputTimer = P_SHELLLIFE + vRandom.y*0.5; + float outputType = PT_SHELL; + emitVertex(outputPos : POSITION, outputVel : TEXCOORD2, outputTimer : TEXCOORD0, outputType : TEXCOORD1); + + //reset our timer + Timer = secondsPerFirework + vRandom.x*0.4; + } + else + { + Timer -= elapsedTime; + } + + //emit ourselves to keep us alive + emitVertex( Pos : POSITION, Vel : TEXCOORD2, Timer : TEXCOORD0, Type : TEXCOORD1); +} + +// +// Shell type particle handler +// +void GSShellHandler( float3 Pos, float3 Vel, float Timer, float Type, + float elapsedTime, + float globalTime, + sampler1D randomTex, + float3 frameGravity) +{ + if(Timer <= 0) + { + float3 outputPos; + float3 outputVel; + float outputTimer; + float outputType; + + float3 vRandom = float3(0,0,0); + + //time to emit a series of new Ember1s + for(int i=0; i 0) + { + GSGenericHandler(Pos, Vel, Timer, Type, elapsedTime, frameGravity ); + } +} + +// +// Ember2 type particle handler +// +void GSEmber2Handler( float3 Pos, float3 Vel, float Timer, float Type, + float elapsedTime, + float globalTime, + sampler1D randomTex, + float3 frameGravity) +{ + if(Timer <= 0) + { + float3 outputPos; + float3 outputVel; + float outputTimer; + float outputType; + + //time to emit a series of new Ember3s + for(int i=0; i Pos : POSITION, + AttribArray Timer : TEXCOORD0, + AttribArray Type : TEXCOORD1, + AttribArray Vel : TEXCOORD2, + + uniform sampler1D randomTex : TEXUNIT0, + uniform float3 frameGravity, + uniform float globalTime, + uniform float elapsedTime, + uniform float secondsPerFirework + ) +{ + if( Type[0] == PT_LAUNCHER ) + GSLauncherHandler( Pos[0], Vel[0], Timer[0], Type[0], + elapsedTime, globalTime, randomTex, secondsPerFirework); + else if ( Type[0] == PT_SHELL ) + GSShellHandler( Pos[0], Vel[0], Timer[0], Type[0], + elapsedTime, globalTime, randomTex, frameGravity); + else if ( Type[0] == PT_EMBER1 || + Type[0] == PT_EMBER3 ) + GSEmber1Handler( Pos[0], Vel[0], Timer[0], Type[0], + elapsedTime, frameGravity); + else if( Type[0] == PT_EMBER2 ) + GSEmber2Handler( Pos[0], Vel[0], Timer[0], Type[0], + elapsedTime, globalTime, randomTex, frameGravity); +} + +struct ColoredFirework +{ + float3 pos : POSITION; + float4 color : COLOR; + float radius : TEXCOORD0; +}; + +//The vertex shader that prepares the fireworks for display +ColoredFirework DisplayParticles_VS +( + in float3 inPos : POSITION, + in float inTimer : TEXCOORD0, + in float inType : TEXCOORD1, + in float3 inVelocity : TEXCOORD2 + + + //uniform float4x4 worldViewProj +) +{ + ColoredFirework output; + // + // Pass the point through + // + output.pos = inPos; //Multiply by world matrix? + output.radius = 1.5; + + // + // calculate the color + // + if( inType == PT_LAUNCHER ) + { + output.color = float4(1,0.1,0.1,1); + output.radius = 1.0; + } + else if( inType == PT_SHELL ) + { + output.color = float4(0.1,1,1,1); + output.radius = 1.0; + } + else if( inType == PT_EMBER1 ) + { + output.color = float4(1,1,0.1,1); + output.color *= (inTimer / P_EMBER1LIFE ); + } + else if( inType == PT_EMBER2 ) + { + output.color = float4(1,0.1,1,1); + } + else if( inType == PT_EMBER3 ) + { + output.color = float4(1,0.1,0.1,1); + output.color *= (inTimer / P_EMBER3LIFE ); + } + + return output; +} + +//The geometry shader that prepares the fireworks for display +POINT +TRIANGLE_OUT +void DisplayParticles_GS( AttribArray Pos : POSITION, + AttribArray Color : COLOR, + AttribArray Radius : TEXCOORD0, + + uniform float4x4 inverseView, + uniform float4x4 worldViewProj) +{ + //float3 g_positions[4] = { float3( -1, 1, 0 ), float3( 1, 1, 0 ), float3( -1, -1, 0 ), float3( 1, -1, 0 ) }; + float3 g_positions[4] = { float3( -1, 1, 0 ), float3( -1, -1, 0 ), float3( 1, 1, 0 ), float3( 1, -1, 0 ) }; + float2 g_texcoords[4] = { float2(0,1), float2(1,1), float2(0,0), float2(1,0) }; + + + // + // Emit two new triangles + // + for(int i=0; i<4; i++) + { + float3 position = -g_positions[i]*Radius[0]; + position = mul( (float3x3)inverseView, position ) + Pos[0]; + float4 outPos = mul( worldViewProj, float4(position,1.0) ); + + emitVertex(outPos : POSITION, Color[0] : COLOR0, g_texcoords[i] : TEXCOORD0); + } + restartStrip(); +} + +//The pixels shaders that colors the fireworks +float4 DisplayParticles_PS( float2 iTexCoord : TEXCOORD0, + float4 iColor : COLOR0, + uniform sampler diffuseTex : register(s0)) : COLOR +{ + return tex2D(diffuseTex, iTexCoord) * iColor; + //return float4(iTexCoord.x, iTexCoord.y, 0, 1) + iColor * 0.01; + //return float4(iTexCoord.xy, 0, 1) * 0.3 + tex2D(diffuseTex, iTexCoord) * 0.7 + iColor * 0.01; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/ParticleGS.hlsl b/res/dist/media/materials/programs/ParticleGS.hlsl new file mode 100644 index 00000000000..eaab46c3714 --- /dev/null +++ b/res/dist/media/materials/programs/ParticleGS.hlsl @@ -0,0 +1,316 @@ +// +// Explanation of different particle types +// +#define PT_LAUNCHER 0 //Firework Launcher - launches a PT_SHELL every so many seconds +#define PT_SHELL 1 //Unexploded shell - flies from the origin and explodes into many PT_EMBERXs +#define PT_EMBER1 2 //basic particle - after it's emitted from the shell, it dies +#define PT_EMBER2 3 //after it's emitted, it explodes again into many PT_EMBER1s +#define PT_EMBER3 4 //just a differently colored ember1 +#define P_SHELLLIFE 3.0 +#define P_EMBER1LIFE 2.5 +#define P_EMBER2LIFE 1.5 +#define P_EMBER3LIFE 2.0 + +//These two were originally shader params, but they caused runtime errors +#define NUM_EMBER_1S 30 +#define NUM_EMBER_2S 15 +#define NUM_EMBER_3S 10 +//This one was originally a variant, but this also causes runtime errors +//#define MAX_EMBER_2S 15.0 + +// +// Generic particle motion handler +// + +struct VSParticleIn +{ + float3 pos : POSITION; + float timer : TIMER; + float type : TYPE; + float3 vel : VELOCITY; +}; + +struct VSParticleDrawOut +{ + float3 pos : POSITION; + float4 color : COLOR0; + float radius : RADIUS; +}; + +struct PSSceneIn +{ + float4 pos : SV_Position; + float2 tex : TEXTURE0; + float4 color : COLOR0; +}; + +SamplerState g_samPoint +{ + Filter = MIN_MAG_MIP_POINT; + AddressU = Wrap; +}; + +SamplerState g_samLinear +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Clamp; + AddressV = Clamp; +}; + +void GSGenericHandler( VSParticleIn input + , float elapsedTime + , float3 frameGravity + , inout PointStream OutputStream + ) +{ + input.pos.xyz += input.vel * elapsedTime; + input.vel += frameGravity; + input.timer -= elapsedTime; + if (input.pos.y > -100) + { + OutputStream.Append(input); + } +} + +// +// Sample a random direction from our random texture +// +float3 RandomDir(float fOffset, float globalTime, Texture1D randomTex) +{ + float2 tCoord; + tCoord.x = (globalTime + fOffset) / 300.0; + tCoord.y = 0.5; + return randomTex.SampleLevel(g_samPoint, tCoord.x, 0).rgb; +} + +// +// Launcher type particle handler +// +void GSLauncherHandler( VSParticleIn input, + float elapsedTime, + float globalTime, + Texture1D randomTex, + float secondsPerFirework, + inout PointStream outputStream) +{ + if(input.timer <= 0) + { + VSParticleIn gsOutput; + float3 vRandom = normalize( RandomDir( input.type, globalTime, randomTex) ); + //Give it more of an up bias + vRandom = normalize(vRandom + float3(0,2.5,0)); + + //time to emit a new SHELL + gsOutput.pos.xyz = input.pos.xyz + input.vel*elapsedTime; + gsOutput.vel = input.vel + vRandom*35.0; + gsOutput.timer = P_SHELLLIFE + vRandom.y*0.5; + gsOutput.type = PT_SHELL; + + outputStream.Append(gsOutput); + + //reset our timer + input.timer = secondsPerFirework + vRandom.x*0.4; + } + else + { + input.timer -= elapsedTime; + } + + //emit ourselves to keep us alive + outputStream.Append(input); +} + +// +// Shell type particle handler +// +void GSShellHandler( VSParticleIn input, + float elapsedTime, + float globalTime, + Texture1D randomTex, + float3 frameGravity, + inout PointStream outputStream) +{ + if(input.timer <= 0) + { + VSParticleIn gsOutput; + + float3 vRandom = float3(0,0,0); + + //time to emit a series of new Ember1s + { + for(int i=0; i outputStream) +{ + if(input.timer > 0) + { + GSGenericHandler(input, elapsedTime, frameGravity, outputStream); + } +} + +// +// Ember2 type particle handler +// +void GSEmber2Handler(VSParticleIn input + , float elapsedTime + , float globalTime + , Texture1D randomTex + , float3 frameGravity + , inout PointStream outputStream) +{ + VSParticleIn gsOutput; + if(input.timer <= 0) + { + //time to emit a series of new Ember3s + for(int i=0; i ParticleOutputStream + , uniform Texture1D randomTex : TEXUNIT0 + , uniform float3 frameGravity + , uniform float globalTime + , uniform float elapsedTime + , uniform float secondsPerFirework + ) +{ + + if( input[0].type == PT_LAUNCHER ) + GSLauncherHandler( input[0], elapsedTime, globalTime, randomTex, secondsPerFirework, ParticleOutputStream); + else if ( input[0].type == PT_SHELL ) + GSShellHandler( input[0], elapsedTime, globalTime, randomTex, frameGravity, ParticleOutputStream); + else if ( input[0].type == PT_EMBER1 ||input[0].type == PT_EMBER3 ) + GSEmber1Handler( input[0], elapsedTime, frameGravity, ParticleOutputStream); + else if( input[0].type == PT_EMBER2 ) + GSEmber2Handler( input[0], elapsedTime, globalTime, randomTex, frameGravity, ParticleOutputStream); +} + +//The vertex shader that prepares the fireworks for display +VSParticleDrawOut DisplayParticles_VS(VSParticleIn input) +{ + VSParticleDrawOut output; + // + // Pass the point through + // + output.pos = input.pos; //Multiply by world matrix? + output.radius = 1.5; + + // + // calculate the color + // + if( input.type == PT_LAUNCHER ) + { + output.color = float4(1,0.1,0.1,1); + output.radius = 1.0; + } + else if( input.type == PT_SHELL ) + { + output.color = float4(0.1,1,1,1); + output.radius = 1.0; + } + else if( input.type == PT_EMBER1 ) + { + output.color = float4(1,1,0.1,1); + output.color *= (input.timer / P_EMBER1LIFE ); + } + else if( input.type == PT_EMBER2 ) + { + output.color = float4(1,0.1,1,1); + } + else if( input.type == PT_EMBER3 ) + { + output.color = float4(1,0.1,0.1,1); + output.color *= (input.timer / P_EMBER3LIFE ); + } + + return output; +} + +//The geometry shader that prepares the fireworks for display +[maxvertexcount(4)] +void DisplayParticles_GS( point VSParticleDrawOut input[1] + , uniform float4x4 inverseView + , uniform float4x4 worldViewProj + , inout TriangleStream SpriteStream) +{ + float3 g_positions[4] = { float3( -1, 1, 0 ), float3( -1, -1, 0 ), float3( 1, 1, 0 ), float3( 1, -1, 0 ) }; + float2 g_texcoords[4] = { float2(0,1), float2(1,1), float2(0,0), float2(1,0) }; + + PSSceneIn output; + + // + // Emit two new triangles + // + for(int i=0; i<4; i++) + { + float3 position = -g_positions[i]*input[0].radius; + position = mul( (float3x3)inverseView, position ) + input[0].pos.xyz; + output.pos = mul( worldViewProj, float4(position,1.0) ); + output.tex = g_texcoords[i]; + output.color = input[0].color; + SpriteStream.Append(output); + } + SpriteStream.RestartStrip(); +} + +//The pixels shaders that colors the fireworks +float4 DisplayParticles_PS( PSSceneIn input + , uniform Texture2D diffuseTex) : SV_Target +{ + return diffuseTex.Sample(g_samLinear, input.tex) * input.color; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/PassthroughFP.cg b/res/dist/media/materials/programs/PassthroughFP.cg new file mode 100644 index 00000000000..3da7ca5d897 --- /dev/null +++ b/res/dist/media/materials/programs/PassthroughFP.cg @@ -0,0 +1,14 @@ +float4 main (float4 pos : POSITION, uniform float4 colour) : COLOR +{ + return colour; +} + +float4 mainCg (float4 colour0 : COLOR) : COLOR +{ + return colour0; +} + +float4 mainForAmbientOneTexture (float4 pos : POSITION, float2 oUv : TEXCOORD0, float4 colour0 : COLOR, uniform float4 colour) : COLOR +{ + return colour; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/PassthroughFP.glsl b/res/dist/media/materials/programs/PassthroughFP.glsl new file mode 100644 index 00000000000..2b4c333a948 --- /dev/null +++ b/res/dist/media/materials/programs/PassthroughFP.glsl @@ -0,0 +1,9 @@ +varying vec4 colour; + +/* + Basic ambient lighting fragment program for GLSL ES +*/ +void main() +{ + gl_FragColor = colour; +} diff --git a/res/dist/media/materials/programs/PassthroughFP.glsles b/res/dist/media/materials/programs/PassthroughFP.glsles new file mode 100644 index 00000000000..eb60077ff55 --- /dev/null +++ b/res/dist/media/materials/programs/PassthroughFP.glsles @@ -0,0 +1,14 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec4 colour; + +/* + Basic ambient lighting fragment program for GLSL ES +*/ +void main() +{ + gl_FragColor = colour; +} diff --git a/res/dist/media/materials/programs/PassthroughVP.glsl b/res/dist/media/materials/programs/PassthroughVP.glsl new file mode 100644 index 00000000000..a58a0f5050b --- /dev/null +++ b/res/dist/media/materials/programs/PassthroughVP.glsl @@ -0,0 +1,5 @@ +void main() +{ + //Transform the vertex (ModelViewProj matrix) + gl_Position = ftransform(); +} diff --git a/res/dist/media/materials/programs/PassthroughVP.glsles b/res/dist/media/materials/programs/PassthroughVP.glsles new file mode 100644 index 00000000000..35494c58f52 --- /dev/null +++ b/res/dist/media/materials/programs/PassthroughVP.glsles @@ -0,0 +1,13 @@ +#version 100 + +precision mediump int; +precision mediump float; + +attribute vec4 position; +uniform mat4 worldViewProj; + +void main() +{ + //Transform the vertex (ModelViewProj matrix) + gl_Position = position * worldViewProj; +} diff --git a/res/dist/media/materials/programs/PosterizeFP.cg b/res/dist/media/materials/programs/PosterizeFP.cg new file mode 100644 index 00000000000..05a26601f33 --- /dev/null +++ b/res/dist/media/materials/programs/PosterizeFP.cg @@ -0,0 +1,17 @@ +sampler2D RT : register(s0); + +float4 Posterize_ps (float4 pos : POSITION, float2 iTexCoord : TEXCOORD0) : COLOR +{ + + float nColors = 8; + float gamma = 0.6; + + float4 texCol = tex2D(RT, iTexCoord); + float3 tc = texCol.xyz; + tc = pow(tc, gamma); + tc = tc * nColors; + tc = floor(tc); + tc = tc / nColors; + tc = pow(tc,1.0/gamma); + return float4(tc,texCol.w); +} diff --git a/res/dist/media/materials/programs/PosterizeFP.glsles b/res/dist/media/materials/programs/PosterizeFP.glsles new file mode 100644 index 00000000000..4ea67d9e72a --- /dev/null +++ b/res/dist/media/materials/programs/PosterizeFP.glsles @@ -0,0 +1,22 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D RT; +varying vec2 uv0; + +void main() +{ + float nColors = 8.0; + float gamma = 0.6; + + vec4 texCol = vec4(texture2D(RT, uv0)); + vec3 tc = texCol.xyz; + tc = pow(tc, vec3(gamma)); + tc = tc * nColors; + tc = floor(tc); + tc = tc / nColors; + tc = pow(tc, vec3(1.0/gamma)); + gl_FragColor = vec4(tc, texCol.w); +} diff --git a/res/dist/media/materials/programs/Radial_Blur_FP.cg b/res/dist/media/materials/programs/Radial_Blur_FP.cg new file mode 100644 index 00000000000..32555cbccbe --- /dev/null +++ b/res/dist/media/materials/programs/Radial_Blur_FP.cg @@ -0,0 +1,58 @@ +//------------------------------------------------------ +//Radial_Blur_FP.cg +// Implements radial blur to be used with the compositor +// It's very dependent on screen resolution +//------------------------------------------------------ + +uniform sampler2D tex: register(s0); + +static const float samples[10] = +{ +-0.08, +-0.05, +-0.03, +-0.02, +-0.01, +0.01, +0.02, +0.03, +0.05, +0.08 +}; + +float4 main(float4 Pos : POSITION, + float2 texCoord: TEXCOORD0, + uniform float sampleDist, + uniform float sampleStrength + ) : COLOR +{ + //Vector from pixel to the center of the screen + float2 dir = 0.5 - texCoord; + + //Distance from pixel to the center (distant pixels have stronger effect) + //float dist = distance( float2( 0.5, 0.5 ), texCoord ); + float dist = sqrt( dir.x*dir.x + dir.y*dir.y ); + + + //Now that we have dist, we can normlize vector + dir = normalize( dir ); + + //Save the color to be used later + float4 color = tex2D( tex, texCoord ); + //Average the pixels going along the vector + float4 sum = color; + for (int i = 0; i < 10; i++) + { + float4 res=tex2D( tex, texCoord + dir * samples[i] * sampleDist ); + sum += res; + } + sum /= 11; + + //Calculate amount of blur based on + //distance and a strength parameter + float t = dist * sampleStrength; + t = saturate( t );//We need 0 <= t <= 1 + + //Blend the original color with the averaged pixels + return lerp( color, sum, t ); +} diff --git a/res/dist/media/materials/programs/Radial_Blur_FP.glsles b/res/dist/media/materials/programs/Radial_Blur_FP.glsles new file mode 100644 index 00000000000..f04c049b342 --- /dev/null +++ b/res/dist/media/materials/programs/Radial_Blur_FP.glsles @@ -0,0 +1,62 @@ +#version 100 + +precision mediump int; +precision mediump float; + +//------------------------------------------------------ +//Radial_Blur_FP.cg +// Implements radial blur to be used with the compositor +// It's very dependent on screen resolution +//------------------------------------------------------ + +uniform sampler2D tex; +uniform float sampleDist; +uniform float sampleStrength; + +varying vec2 uv; + +void main() +{ + float samples[10]; + + samples[0] = -0.08; + samples[1] = -0.05; + samples[2] = -0.03; + samples[3] = -0.02; + samples[4] = -0.01; + samples[5] = 0.01; + samples[6] = 0.02; + samples[7] = 0.03; + samples[8] = 0.05; + samples[9] = 0.08; + + //Vector from pixel to the center of the screen + vec2 dir = 0.5 - uv; + + //Distance from pixel to the center (distant pixels have stronger effect) + //float dist = distance( vec2( 0.5, 0.5 ), texCoord ); + float dist = sqrt( dir.x*dir.x + dir.y*dir.y ); + + + //Now that we have dist, we can normlize vector + dir = normalize( dir ); + + //Save the color to be used later + vec4 color = texture2D( tex, uv ); + //Average the pixels going along the vector + vec4 sum = color; + for (int i = 0; i < 10; i++) + { + vec4 res=texture2D( tex, uv + dir * samples[i] * sampleDist ); + sum += res; + } + sum /= 11.0; + + //Calculate amount of blur based on + //distance and a strength parameter + float t = dist * sampleStrength; + t = clamp( t, 0.0, 1.0 );//We need 0 <= t <= 1 + + //Blend the original color with the averaged pixels + gl_FragColor = mix( color, sum, t ); +} diff --git a/res/dist/media/materials/programs/Radial_Blur_FP.hlsl b/res/dist/media/materials/programs/Radial_Blur_FP.hlsl new file mode 100644 index 00000000000..3e95a4d8958 --- /dev/null +++ b/res/dist/media/materials/programs/Radial_Blur_FP.hlsl @@ -0,0 +1,58 @@ +//------------------------------------------------------ +//Radial_Blur_FP.cg +// Implements radial blur to be used with the compositor +// It's very dependent on screen resolution +//------------------------------------------------------ + +uniform sampler2D tex: register(s0); + +static const float samples[10] = +{ +-0.08, +-0.05, +-0.03, +-0.02, +-0.01, +0.01, +0.02, +0.03, +0.05, +0.08 +}; + +float4 main(float4 Pos : SV_POSITION, + float2 texCoord: TEXCOORD0, + uniform float sampleDist, + uniform float sampleStrength + ) : COLOR +{ + //Vector from pixel to the center of the screen + float2 dir = 0.5 - texCoord; + + //Distance from pixel to the center (distant pixels have stronger effect) + //float dist = distance( float2( 0.5, 0.5 ), texCoord ); + float dist = sqrt( dir.x*dir.x + dir.y*dir.y ); + + + //Now that we have dist, we can normlize vector + dir = normalize( dir ); + + //Save the color to be used later + float4 color = tex2D( tex, texCoord ); + //Average the pixels going along the vector + float4 sum = color; + for (int i = 0; i < 10; i++) + { + float4 res=tex2D( tex, texCoord + dir * samples[i] * sampleDist ); + sum += res; + } + sum /= 11; + + //Calculate amount of blur based on + //distance and a strength parameter + float t = dist * sampleStrength; + t = saturate( t );//We need 0 <= t <= 1 + + //Blend the original color with the averaged pixels + return lerp( color, sum, t ); +} diff --git a/res/dist/media/materials/programs/ShaderInstancing.cg b/res/dist/media/materials/programs/ShaderInstancing.cg new file mode 100644 index 00000000000..02f243908ad --- /dev/null +++ b/res/dist/media/materials/programs/ShaderInstancing.cg @@ -0,0 +1,101 @@ +//--------------------------------------------------------------------------- +//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 BlendIdx : BLENDINDICES; + float4 BlendWgt : BLENDWEIGHT; +}; + +#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 ST_DUAL_QUATERNION + uniform float2x4 worldDualQuaternion2x4Array[120] +#else + uniform float3x4 worldMatrix3x4Array[80] +#endif +#if defined( DEPTH_SHADOWCASTER ) || defined( DEPTH_SHADOWRECEIVER ) + , uniform float4 depthRange +#endif +#ifdef DEPTH_SHADOWRECEIVER + , uniform float4x4 texViewProjMatrix +#endif + ) +{ + VS_OUTPUT output; + + float4 worldPos = 0; + float3 worldNorm = 0; + + int idx = int(input.BlendIdx[0]); +#ifdef ST_DUAL_QUATERNION + //Only dealing with one weight so normalization of the dual quaternion and weighting are unnecessary + float2x4 blendDQ = worldDualQuaternion2x4Array[idx]; +#ifdef BONE_TWO_WEIGHTS + float2x4 blendDQ2 = worldDualQuaternion2x4Array[int(input.BlendIdx[1])]; + + //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.BlendWgt.x; + blendDQ += input.BlendWgt.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 + worldPos = float4( mul( worldMatrix3x4Array[idx], input.Position ).xyz, 1.0f ); + worldNorm = mul( (float3x3)(worldMatrix3x4Array[idx]), input.Normal ); +#endif + + /*int i; + for( i=0; i<4; i++ ) + { + int idx = int(input.BlendIdx[0]); + worldPos += float4( mul( worldMatrix3x4Array[idx], input.Position ).xyz, 1.0f ) * input.BlendWgt[i]; + worldNorm += mul( (float3x3)(worldMatrix3x4Array[idx]), input.Normal ) * input.BlendWgt[i]; + }*/ + + //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/ShaderInstancing.vert b/res/dist/media/materials/programs/ShaderInstancing.vert new file mode 100644 index 00000000000..425341ed1c5 --- /dev/null +++ b/res/dist/media/materials/programs/ShaderInstancing.vert @@ -0,0 +1,117 @@ +//--------------------------------------------------------------------------- +//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 mat4x3 worldMatrix3x4Array[80]; +#ifdef ST_DUAL_QUATERNION +uniform vec4 worldDualQuaternion2x4Array[240]; +#else +uniform vec4 worldMatrix3x4Array[240]; //240 = 80*3 +#endif + + +#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 + int idx = int(blendIndices[0]) * 2; + mat2x4 blendDQ; + blendDQ[0] = worldDualQuaternion2x4Array[idx]; + blendDQ[1] = worldDualQuaternion2x4Array[idx + 1]; +#ifdef BONE_TWO_WEIGHTS + int idx2 = int(blendIndices[1]) * 2; + mat2x4 blendDQ2; + blendDQ2[0] = worldDualQuaternion2x4Array[idx2]; + blendDQ2[1] = worldDualQuaternion2x4Array[idx2 + 1]; + + //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; + int idx = int(blendIndices[0]) * 3; + worldMatrix[0] = worldMatrix3x4Array[idx]; + worldMatrix[1] = worldMatrix3x4Array[idx + 1]; + worldMatrix[2] = worldMatrix3x4Array[idx + 2]; + worldMatrix[3] = vec4( 0, 0, 0, 1 ); + + worldPos = vertex * worldMatrix; + worldNorm = normal * mat3(worldMatrix); +#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/SharpenEdgesFP.cg b/res/dist/media/materials/programs/SharpenEdgesFP.cg new file mode 100644 index 00000000000..85f30fb4949 --- /dev/null +++ b/res/dist/media/materials/programs/SharpenEdgesFP.cg @@ -0,0 +1,23 @@ +sampler2D RT: register(s0); + +float4 sharpenEdges_fp( float4 pos : POSITION, float2 iTexCoord: TEXCOORD0, uniform float2 vTexelSize) : COLOR +{ + + float2 usedTexelED[8] = { + -1, -1, + 0, -1, + 1, -1, + -1, 0, + 1, 0, + -1, 1, + 0, 1, + 1, 1, + }; + + float4 cAvgColor= 9 * tex2D (RT, iTexCoord); + + for(int t=0; t<8; t++) + cAvgColor -= tex2D(RT, iTexCoord + vTexelSize * usedTexelED[t]); + + return cAvgColor; +} diff --git a/res/dist/media/materials/programs/SharpenEdgesFP.glsles b/res/dist/media/materials/programs/SharpenEdgesFP.glsles new file mode 100644 index 00000000000..e8bf265ce66 --- /dev/null +++ b/res/dist/media/materials/programs/SharpenEdgesFP.glsles @@ -0,0 +1,31 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D RT; + +uniform vec2 vTexelSize; +varying vec2 uv0; +varying vec2 uv1; + +void main() +{ + vec2 usedTexelED[8]; + usedTexelED[0] = vec2(-1, -1); + usedTexelED[1] = vec2(0, -1); + usedTexelED[2] = vec2(1, -1); + usedTexelED[3] = vec2(-1, 0); + usedTexelED[4] = vec2(1, 0); + usedTexelED[5] = vec2(-1, 1); + usedTexelED[6] = vec2(0, 1); + usedTexelED[7] = vec2(1, 1); + + mediump vec4 tc = texture2D(RT, uv0); + vec4 cAvgColor = vec4(9.0 * tc); + + for(int t=0; t<8; t++) + cAvgColor -= texture2D(RT, uv0 + vTexelSize * usedTexelED[t]); + + gl_FragColor = cAvgColor; +} diff --git a/res/dist/media/materials/programs/ShowNormals.glsles b/res/dist/media/materials/programs/ShowNormals.glsles new file mode 100644 index 00000000000..3b149f1b412 --- /dev/null +++ b/res/dist/media/materials/programs/ShowNormals.glsles @@ -0,0 +1,16 @@ +#version 100 +precision mediump int; +precision mediump float; + +attribute vec4 position; +attribute vec3 normal; + +varying vec4 oUv0; + +uniform mat4 worldViewProj; + +void main() +{ + gl_Position = worldViewProj * position; + oUv0 = vec4(normal, 1.0); +} diff --git a/res/dist/media/materials/programs/ShowTangents.glsles b/res/dist/media/materials/programs/ShowTangents.glsles new file mode 100644 index 00000000000..7691d86ce81 --- /dev/null +++ b/res/dist/media/materials/programs/ShowTangents.glsles @@ -0,0 +1,16 @@ +#version 100 +precision mediump int; +precision mediump float; + +attribute vec4 position; +attribute vec3 tangent; + +varying vec4 oUv0; + +uniform mat4 worldViewProj; + +void main() +{ + gl_Position = worldViewProj * position; + oUv0 = vec4(tangent, 1.0); +} diff --git a/res/dist/media/materials/programs/ShowUV.glsles b/res/dist/media/materials/programs/ShowUV.glsles new file mode 100644 index 00000000000..1a4e5887f9d --- /dev/null +++ b/res/dist/media/materials/programs/ShowUV.glsles @@ -0,0 +1,12 @@ +#version 100 +precision mediump int; +precision mediump float; + +varying vec2 ambientUV; + +// Basic fragment program to display UV +void main() +{ + // wrap values using fract + gl_FragColor = vec4(fract(ambientUV.x), fract(ambientUV.y), 0.0, 1.0); +} diff --git a/res/dist/media/materials/programs/ShowUVdir3D.glsles b/res/dist/media/materials/programs/ShowUVdir3D.glsles new file mode 100644 index 00000000000..10676248fc2 --- /dev/null +++ b/res/dist/media/materials/programs/ShowUVdir3D.glsles @@ -0,0 +1,14 @@ +#version 100 +precision mediump int; +precision mediump float; + +varying vec4 oUv0; + +// Basic fragment program to display 3d uv +void main() +{ + vec3 n = normalize(oUv0.xyz); + gl_FragColor = vec4(n.x, n.y, n.z, 1.0); +} + + diff --git a/res/dist/media/materials/programs/StdQuad_Tex2_vp.glsles b/res/dist/media/materials/programs/StdQuad_Tex2_vp.glsles new file mode 100644 index 00000000000..76f01e4d92d --- /dev/null +++ b/res/dist/media/materials/programs/StdQuad_Tex2_vp.glsles @@ -0,0 +1,23 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +attribute vec4 vertex; +varying vec2 uv0; +varying vec2 uv1; +varying vec4 pos; + +void main() +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + gl_Position = worldViewProj * vertex; + + // The input positions adjusted by texel offsets, so clean up inaccuracies + vec2 inPos = sign(vertex.xy); + + // Convert to image-space + uv0 = (vec2(inPos.x, -inPos.y) + 1.0) * 0.5; + uv1 = uv0; +} diff --git a/res/dist/media/materials/programs/StdQuad_Tex2a_vp.glsles b/res/dist/media/materials/programs/StdQuad_Tex2a_vp.glsles new file mode 100644 index 00000000000..55911ea2017 --- /dev/null +++ b/res/dist/media/materials/programs/StdQuad_Tex2a_vp.glsles @@ -0,0 +1,23 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +attribute vec4 vertex; +varying vec2 uv0; +varying vec2 uv1; +varying vec4 pos; + +void main() +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + gl_Position = worldViewProj * vertex; + + // The input positions adjusted by texel offsets, so clean up inaccuracies + vec2 inPos = sign(vertex.xy); + + // Convert to image-space + uv0 = (vec2(inPos.x, -inPos.y) + 1.0) * 0.5; + uv1 = inPos.xy; +} diff --git a/res/dist/media/materials/programs/StdQuad_Tex3_vp.glsles b/res/dist/media/materials/programs/StdQuad_Tex3_vp.glsles new file mode 100644 index 00000000000..7c5d5fdec97 --- /dev/null +++ b/res/dist/media/materials/programs/StdQuad_Tex3_vp.glsles @@ -0,0 +1,25 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +attribute vec4 vertex; +varying vec2 uv0; +varying vec2 uv1; +varying vec2 uv2; +varying vec4 pos; + +void main() +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + gl_Position = worldViewProj * vertex; + + // The input positions adjusted by texel offsets, so clean up inaccuracies + vec2 inPos = sign(vertex.xy); + + // Convert to image-space + uv0 = (vec2(inPos.x, -inPos.y) + 1.0) * 0.5; + uv1 = uv0; + uv2 = uv0; +} diff --git a/res/dist/media/materials/programs/StdQuad_Tex4_vp.glsles b/res/dist/media/materials/programs/StdQuad_Tex4_vp.glsles new file mode 100644 index 00000000000..2d504b892a3 --- /dev/null +++ b/res/dist/media/materials/programs/StdQuad_Tex4_vp.glsles @@ -0,0 +1,27 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +attribute vec4 vertex; +varying vec2 uv0; +varying vec2 uv1; +varying vec2 uv2; +varying vec2 uv3; +varying vec4 pos; + +void main() +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + gl_Position = worldViewProj * vertex; + + // The input positions adjusted by texel offsets, so clean up inaccuracies + vec2 inPos = sign(vertex.xy); + + // Convert to image-space + uv0 = (vec2(inPos.x, -inPos.y) + 1.0) * 0.5; + uv1 = uv0; + uv2 = uv0; + uv3 = uv0; +} diff --git a/res/dist/media/materials/programs/StdQuad_vp.cg b/res/dist/media/materials/programs/StdQuad_vp.cg new file mode 100644 index 00000000000..cfa9f0a1fb4 --- /dev/null +++ b/res/dist/media/materials/programs/StdQuad_vp.cg @@ -0,0 +1,113 @@ +void StdQuad_vp +( + in float4 inPos : POSITION, + + out float4 pos : POSITION, + out float2 uv0 : TEXCOORD0, + + uniform float4x4 worldViewProj +) +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + pos = mul(worldViewProj, inPos); + + // The input positions adjusted by texel offsets, so clean up inaccuracies + inPos.xy = sign(inPos.xy); + + // Convert to image-space + uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f; +} + +void StdQuad_Tex2_vp +( + in float4 inPos : POSITION, + + out float4 pos : POSITION, + out float2 uv0 : TEXCOORD0, + out float2 uv1 : TEXCOORD1, + + uniform float4x4 worldViewProj +) +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + pos = mul(worldViewProj, inPos); + + // The input positions adjusted by texel offsets, so clean up inaccuracies + inPos.xy = sign(inPos.xy); + + // Convert to image-space + uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f; + uv1 = uv0; +} + +void StdQuad_Tex2a_vp +( + in float4 inPos : POSITION, + + out float4 pos : POSITION, + out float2 uv0 : TEXCOORD0, + out float2 uv1 : TEXCOORD1, + + uniform float4x4 worldViewProj +) +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + pos = mul(worldViewProj, inPos); + + // The input positions adjusted by texel offsets, so clean up inaccuracies + inPos.xy = sign(inPos.xy); + + // Convert to image-space + uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f; + uv1 = inPos.xy; +} + +void StdQuad_Tex3_vp +( + in float4 inPos : POSITION, + + out float4 pos : POSITION, + out float2 uv0 : TEXCOORD0, + out float2 uv1 : TEXCOORD1, + out float2 uv2 : TEXCOORD2, + + uniform float4x4 worldViewProj +) +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + pos = mul(worldViewProj, inPos); + + // The input positions adjusted by texel offsets, so clean up inaccuracies + inPos.xy = sign(inPos.xy); + + // Convert to image-space + uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f; + uv1 = uv0; + uv2 = uv0; +} + +void StdQuad_Tex4_vp +( + in float4 inPos : POSITION, + + out float4 pos : POSITION, + out float2 uv0 : TEXCOORD0, + out float2 uv1 : TEXCOORD1, + out float2 uv2 : TEXCOORD2, + out float2 uv3 : TEXCOORD3, + + uniform float4x4 worldViewProj +) +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + pos = mul(worldViewProj, inPos); + + // The input positions adjusted by texel offsets, so clean up inaccuracies + inPos.xy = sign(inPos.xy); + + // Convert to image-space + uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f; + uv1 = uv0; + uv2 = uv0; + uv3 = uv0; +} diff --git a/res/dist/media/materials/programs/StdQuad_vp.glsl b/res/dist/media/materials/programs/StdQuad_vp.glsl new file mode 100644 index 00000000000..ca6c3ebdb57 --- /dev/null +++ b/res/dist/media/materials/programs/StdQuad_vp.glsl @@ -0,0 +1,11 @@ +varying vec2 uv; + +void main() +{ + gl_Position = ftransform(); + + vec2 inPos = sign(gl_Vertex.xy); + + uv = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; +} + diff --git a/res/dist/media/materials/programs/StdQuad_vp.glsles b/res/dist/media/materials/programs/StdQuad_vp.glsles new file mode 100644 index 00000000000..6056bef04b4 --- /dev/null +++ b/res/dist/media/materials/programs/StdQuad_vp.glsles @@ -0,0 +1,17 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +attribute vec4 vertex; +varying vec2 uv; + +void main() +{ + gl_Position = worldViewProj * vertex; + + vec2 inPos = sign(vertex.xy); + + uv = (vec2(inPos.x, -inPos.y) + 1.0) / 2.0; +} diff --git a/res/dist/media/materials/programs/StdQuad_vp.hlsl b/res/dist/media/materials/programs/StdQuad_vp.hlsl new file mode 100644 index 00000000000..6e6e2fcebd5 --- /dev/null +++ b/res/dist/media/materials/programs/StdQuad_vp.hlsl @@ -0,0 +1,20 @@ +void StdQuad_vp +( + in float4 inPos : POSITION, + + out float4 pos : POSITION, + out float2 uv0 : TEXCOORD0, + + uniform float4x4 worldViewProj +) +{ + // Use standardise transform, so work accord with render system specific (RS depth, requires texture flipping, etc) + pos = mul(worldViewProj, inPos); + + // The input positions adjusted by texel offsets, so clean up inaccuracies + inPos.xy = sign(inPos.xy); + + // Convert to image-space + uv0 = (float2(inPos.x, -inPos.y) + 1.0f) * 0.5f; +} + diff --git a/res/dist/media/materials/programs/Swizzle.gp b/res/dist/media/materials/programs/Swizzle.gp new file mode 100644 index 00000000000..929c4e616ed --- /dev/null +++ b/res/dist/media/materials/programs/Swizzle.gp @@ -0,0 +1,39 @@ +!!NVgp4.0 +PRIMITIVE_IN TRIANGLES; +PRIMITIVE_OUT TRIANGLE_STRIP; +VERTICES_OUT 6; +# cgc version 2.0.0015, build date May 15 2008 +# command line args: -profile gpu_gp +# source file: gs_simple.cg +#vendor NVIDIA Corporation +#version 2.0.0.15 +#profile gpu_gp +#program geometry_swizzle +#semantic geometry_swizzle.position : POSITION +#var float4 position.__data[0] : $vin.VERTEX[0].POSITION : HPOS[0][32] : 0 : 1 +#var float4 position.__data[1] : $vin.VERTEX[1].POSITION : HPOS[1][32] : 0 : 1 +#var float4 position.__data[2] : $vin.VERTEX[2].POSITION : HPOS[2][32] : 0 : 1 +ATTRIB vertex_position = vertex.position; +TEMP RC, HC; +MOV.F result.position, vertex[0].position; +MOV.F result.color, {1, 0}.xyyx; +EMIT; +MOV.F result.position, vertex[1].position; +MOV.F result.color, {1, 0}.xyyx; +EMIT; +MOV.F result.position, vertex[2].position; +MOV.F result.color, {1, 0}.xyyx; +EMIT; +ENDPRIM; +MOV.F result.position, vertex[0].position.yxzw; +MOV.F result.color, {0, 1}.xxyy; +EMIT; +MOV.F result.position, vertex[1].position.yxzw; +MOV.F result.color, {0, 1}.xxyy; +EMIT; +MOV.F result.position, vertex[2].position.yxzw; +MOV.F result.color, {0, 1}.xxyy; +EMIT; +ENDPRIM; +END +# 20 instructions, 0 R-regs \ No newline at end of file diff --git a/res/dist/media/materials/programs/SwizzleGP.cg b/res/dist/media/materials/programs/SwizzleGP.cg new file mode 100644 index 00000000000..7532c80a552 --- /dev/null +++ b/res/dist/media/materials/programs/SwizzleGP.cg @@ -0,0 +1,14 @@ +// Geometry pass-through program for colored triangles +TRIANGLE void gs_swizzle(AttribArray position : POSITION) +{ + for (int i=0; i 'create' a new vertex + // use EndPrimitive to signal that you are done creating a primitive! + // step b) create a new piece of geometry (I.E. WHY WE ARE USING A GEOMETRY SHADER!) + // I just do the same loop, but swizzle the x and y values + // result => the line we want to draw, and the same line, but along the other axis + + //Pass-thru! + for(i=0; i< gl_VerticesIn; i++){ + gl_Position = gl_PositionIn[i]; + gl_FrontColor = origColor; + EmitVertex(); + } + EndPrimitive(); + //New piece of geometry! We just swizzle the x and y terms + for(i=0; i< gl_VerticesIn; i++){ + gl_Position = gl_PositionIn[i]; + gl_Position.xy = gl_Position.yx; + gl_FrontColor = cloneColor; + EmitVertex(); + } + EndPrimitive(); + +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/SwizzleGP.glsles b/res/dist/media/materials/programs/SwizzleGP.glsles new file mode 100644 index 00000000000..4dff5df2a47 --- /dev/null +++ b/res/dist/media/materials/programs/SwizzleGP.glsles @@ -0,0 +1,80 @@ +#version 120 +#extension GL_EXT_geometry_shader4 : enable + +uniform vec4 origColor; +uniform vec4 cloneColor; + +void main(void) +{ + + //increment variable + int i; + + ///////////////////////////////////////////////////////////// + //This example has two parts + // step a) draw the primitive pushed down the pipeline + // there are gl_Vertices # of vertices + // put the vertex value into gl_Position + // use EmitVertex => 'create' a new vertex + // use EndPrimitive to signal that you are done creating a primitive! + // step b) create a new piece of geometry (I.E. WHY WE ARE USING A GEOMETRY SHADER!) + // I just do the same loop, but swizzle the x and y values + // result => the line we want to draw, and the same line, but along the other axis + + //Pass-thru! + for(i=0; i< gl_VerticesIn; i++){ + gl_Position = gl_PositionIn[i]; + gl_FrontColor = origColor; + EmitVertex(); + } + EndPrimitive(); + //New piece of geometry! We just swizzle the x and y terms + for(i=0; i< gl_VerticesIn; i++){ + gl_Position = gl_PositionIn[i]; + gl_Position.xy = gl_Position.yx; + gl_FrontColor = cloneColor; + EmitVertex(); + } + EndPrimitive(); + +} +#version 120 +#extension GL_EXT_geometry_shader4 : enable + +uniform vec4 origColor; +uniform vec4 cloneColor; + +void main(void) +{ + + //increment variable + int i; + + ///////////////////////////////////////////////////////////// + //This example has two parts + // step a) draw the primitive pushed down the pipeline + // there are gl_Vertices # of vertices + // put the vertex value into gl_Position + // use EmitVertex => 'create' a new vertex + // use EndPrimitive to signal that you are done creating a primitive! + // step b) create a new piece of geometry (I.E. WHY WE ARE USING A GEOMETRY SHADER!) + // I just do the same loop, but swizzle the x and y values + // result => the line we want to draw, and the same line, but along the other axis + + //Pass-thru! + for(i=0; i< gl_VerticesIn; i++){ + gl_Position = gl_PositionIn[i]; + gl_FrontColor = origColor; + EmitVertex(); + } + EndPrimitive(); + //New piece of geometry! We just swizzle the x and y terms + for(i=0; i< gl_VerticesIn; i++){ + gl_Position = gl_PositionIn[i]; + gl_Position.xy = gl_Position.yx; + gl_FrontColor = cloneColor; + EmitVertex(); + } + EndPrimitive(); + +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/TilingFP.cg b/res/dist/media/materials/programs/TilingFP.cg new file mode 100644 index 00000000000..49cb60fce5c --- /dev/null +++ b/res/dist/media/materials/programs/TilingFP.cg @@ -0,0 +1,33 @@ +sampler2D RT : register(s0); + +float4 Tiling_ps(float4 inPos : POSITION, + float2 iTexCoord : TEXCOORD0, + uniform half NumTiles, + uniform half Threshold) : COLOR +{ + + + half3 EdgeColor = {0.7, 0.7, 0.7}; + + half size = 1.0/NumTiles; + half2 Pbase = iTexCoord - fmod(iTexCoord, size.xx); + half2 PCenter = Pbase + (size/2.0).xx; + half2 st = (iTexCoord - Pbase)/size; + half4 c1 = (half4)0; + half4 c2 = (half4)0; + half4 invOff = half4((1-EdgeColor),1); + if (st.x > st.y) { c1 = invOff; } + half threshholdB = 1.0 - Threshold; + if (st.x > threshholdB) { c2 = c1; } + if (st.y > threshholdB) { c2 = c1; } + half4 cBottom = c2; + c1 = (half4)0; + c2 = (half4)0; + if (st.x > st.y) { c1 = invOff; } + if (st.x < Threshold) { c2 = c1; } + if (st.y < Threshold) { c2 = c1; } + half4 cTop = c2; + half4 tileColor = tex2D(RT, PCenter); + half4 result = tileColor + cTop - cBottom; + return result; +} diff --git a/res/dist/media/materials/programs/TilingFP.glsles b/res/dist/media/materials/programs/TilingFP.glsles new file mode 100644 index 00000000000..54cd38bb085 --- /dev/null +++ b/res/dist/media/materials/programs/TilingFP.glsles @@ -0,0 +1,36 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D RT; +uniform float NumTiles; +uniform float Threshold; +varying vec2 uv0; + +void main() +{ + vec3 EdgeColor = vec3(0.7, 0.7, 0.7); + + float size = 1.0/NumTiles; + vec2 Pbase = uv0 - mod(uv0, vec2(size)); + vec2 PCenter = vec2(Pbase + (size/2.0)); + vec2 st = (uv0 - Pbase)/size; + vec4 c1 = vec4(0.0); + vec4 c2 = vec4(0.0); + vec4 invOff = vec4((1.0-EdgeColor),1.0); + if (st.x > st.y) { c1 = invOff; } + float threshholdB = 1.0 - Threshold; + if (st.x > threshholdB) { c2 = c1; } + if (st.y > threshholdB) { c2 = c1; } + vec4 cBottom = c2; + c1 = vec4(0.0); + c2 = vec4(0.0); + if (st.x > st.y) { c1 = invOff; } + if (st.x < Threshold) { c2 = c1; } + if (st.y < Threshold) { c2 = c1; } + vec4 cTop = c2; + vec4 tileColor = vec4(texture2D(RT, PCenter)); + vec4 result = tileColor + cTop - cBottom; + gl_FragColor = result; +} diff --git a/res/dist/media/materials/programs/VTFInstancing.cg b/res/dist/media/materials/programs/VTFInstancing.cg new file mode 100644 index 00000000000..bbcc0aa8daa --- /dev/null +++ b/res/dist/media/materials/programs/VTFInstancing.cg @@ -0,0 +1,107 @@ +//--------------------------------------------------------------------------- +//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 m01 : TEXCOORD1; + float4 m23 : TEXCOORD2; +}; + +#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 = 0; + float3 worldNorm = 0; + +#ifdef ST_DUAL_QUATERNION + float2x4 blendDQ; + blendDQ[0] = tex2D( matrixTexture, input.m01.xy ); + blendDQ[1] = tex2D( matrixTexture, input.m01.zw ); +#ifdef BONE_TWO_WEIGHTS + float2x4 blendDQ2; + //Use the empty parts of m03, z and w, for the second dual quaternion + blendDQ2[0] = tex2D( matrixTexture, input.m23.xy ); + blendDQ2[1] = tex2D( matrixTexture, input.m23.zw ); + + //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 + //Only dealing with one weight so normalization of the dual quaternion and weighting are unnecessary + worldPos = float4(calculateBlendPosition(input.Position.xyz, blendDQ), 1.0); + worldNorm = calculateBlendNormal(input.Normal.xyz, blendDQ); +#else + float3x4 worldMatrix; + worldMatrix[0] = tex2D( matrixTexture, input.m01.xy ); + worldMatrix[1] = tex2D( matrixTexture, input.m01.zw ); + worldMatrix[2] = tex2D( matrixTexture, input.m23.xy ); + + worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f ); + worldNorm= mul( (float3x3)(worldMatrix), input.Normal ); +#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/VTFInstancing.vert b/res/dist/media/materials/programs/VTFInstancing.vert new file mode 100644 index 00000000000..48fb0ed6f91 --- /dev/null +++ b/res/dist/media/materials/programs/VTFInstancing.vert @@ -0,0 +1,113 @@ +//--------------------------------------------------------------------------- +//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; +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, uv1.xy ); + blendDQ[1] = texture2D( matrixTexture, uv1.zy ); +#ifdef BONE_TWO_WEIGHTS + mat2x4 blendDQ2; + blendDQ2[0] = texture2D( matrixTexture, uv2.xy ); + blendDQ2[1] = texture2D( matrixTexture, uv2.zw ); + + //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.xy ); + worldMatrix[1] = texture2D( matrixTexture, uv1.zw ); + worldMatrix[2] = texture2D( matrixTexture, uv2.xy ); + worldMatrix[3] = vec4( 0, 0, 0, 1 ); + + worldPos = vertex * worldMatrix; + worldNorm = normal * mat3(worldMatrix); +#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/crowdVp.glsl b/res/dist/media/materials/programs/crowdVp.glsl new file mode 100644 index 00000000000..cb7a6e04f59 --- /dev/null +++ b/res/dist/media/materials/programs/crowdVp.glsl @@ -0,0 +1,62 @@ +uniform mat4 viewProjectionMatrix; +uniform float numBones; +uniform vec4 worldMatrix3x4Array[240]; +uniform vec4 lightDiffuseColour; +uniform vec4 ambient; +uniform vec4 lightPos; + +attribute vec4 blendIndices; +attribute vec4 blendWeights; + + +void main() +{ + vec3 blendPos = vec3(0,0,0); + vec3 blendNorm = vec3(0,0,0); + + vec3 tmpPos = vec3(0,0,0); + vec3 tmpNorm = vec3(0,0,0); + + + int instanceOffset = int(gl_MultiTexCoord1.x) * 3 * int(numBones); + for (int bone = 0; bone < 2; ++bone) + { + // perform matrix multiplication manually since no 3x4 matrices + for (int row = 0; row < 3; ++row) + { + int idx = instanceOffset + int(blendIndices[bone]) * 3 + row; + vec4 blendMatrixRow = worldMatrix3x4Array[idx]; + tmpPos[row] = dot(blendMatrixRow, gl_Vertex); +#if SHADOW_CASTER +#else + tmpNorm[row] = dot(blendMatrixRow.xyz, gl_Normal); +#endif + + } + // now weight this into final + blendPos += tmpPos * blendWeights[bone]; +#if SHADOW_CASTER +#else + blendNorm += tmpNorm * blendWeights[bone]; +#endif + } + + // apply view / projection to position + gl_Position = viewProjectionMatrix * vec4(blendPos, 1); + + +#if SHADOW_CASTER + gl_FrontColor = ambient; +#else + // simple lighting model + vec3 lightDir = normalize( + lightPos.xyz - (blendPos.xyz * lightPos.w)); + gl_FrontColor = ambient + + clamp(dot(lightDir, blendNorm), 0.0, 1.0) * lightDiffuseColour; +#endif + gl_FrontSecondaryColor = vec4(0); + gl_TexCoord[0] = gl_MultiTexCoord0; + + +} + diff --git a/res/dist/media/materials/programs/crowdVp.glsles b/res/dist/media/materials/programs/crowdVp.glsles new file mode 100644 index 00000000000..29991bc95ca --- /dev/null +++ b/res/dist/media/materials/programs/crowdVp.glsles @@ -0,0 +1,68 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 viewProjectionMatrix; +uniform float numBones; +uniform vec4 worldMatrix3x4Array[240]; +uniform vec4 lightDiffuseColour; +uniform vec4 ambient; +uniform vec4 lightPos; + +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +attribute vec4 vertex; +attribute vec3 normal; +varying vec4 colour; +varying vec4 uv0; +varying vec4 uv1; + +void main() +{ + vec3 blendPos = vec3(0,0,0); + vec3 blendNorm = vec3(0,0,0); + + vec3 tmpPos = vec3(0,0,0); + vec3 tmpNorm = vec3(0,0,0); + + int instanceOffset = int(uv1.x) * 3 * int(numBones); + for (int bone = 0; bone < 2; ++bone) + { + // perform matrix multiplication manually since no 3x4 matrices + for (int row = 0; row < 3; ++row) + { + int idx = instanceOffset + int(blendIndices[bone]) * 3 + row; + vec4 blendMatrixRow = worldMatrix3x4Array[idx]; + tmpPos[row] = dot(blendMatrixRow, vertex); +#if SHADOW_CASTER +#else + tmpNorm[row] = dot(blendMatrixRow.xyz, normal); +#endif + + } + // now weight this into final + blendPos += tmpPos * blendWeights[bone]; +#if SHADOW_CASTER +#else + blendNorm += tmpNorm * blendWeights[bone]; +#endif + } + + // apply view / projection to position + gl_Position = viewProjectionMatrix * vec4(blendPos, 1); + + +#if SHADOW_CASTER + colour = ambient; +#else + // simple lighting model + vec3 lightDir = normalize( + lightPos.xyz - (blendPos.xyz * lightPos.w)); + colour = ambient + + clamp(dot(lightDir, blendNorm), 0.0, 1.0) * lightDiffuseColour; +#endif +// gl_FrontSecondaryColor = vec4(0); +// gl_TexCoord[0] = gl_MultiTexCoord0; +} diff --git a/res/dist/media/materials/programs/depthshadowobject.cg b/res/dist/media/materials/programs/depthshadowobject.cg new file mode 100644 index 00000000000..b1ae63eac42 --- /dev/null +++ b/res/dist/media/materials/programs/depthshadowobject.cg @@ -0,0 +1,185 @@ +/* Copyright Torus Knot Software Ltd 2000-2012 + +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. +*/ +#include "shadows.cg" + +#define BIAS 0 + +struct VS_OUT +{ + float4 pos : POSITION; + float3 diffuseUV : TEXCOORD0; // xy = UV, z = fog/depth +#if !SHADOWCASTER + float3 col : COLOR; +#endif +#if DEPTH_SHADOWCASTER + float depth : TEXCOORD1; +#endif +#if DEPTH_SHADOWRECEIVER + float4 lightSpacePos0 : TEXCOORD2; + float4 lightSpacePos1 : TEXCOORD3; + float4 lightSpacePos2 : TEXCOORD4; +#endif +}; + +VS_OUT main_vp( + float4 pos : POSITION, + float3 normal : NORMAL, + float4 uv0 : TEXCOORD0, + + uniform float4x4 worldViewProj, + uniform float4 lightPosition, + uniform float3 lightDiffuse +#if FOG + , uniform float2 fogParams // x = fog start, y = fog distance +#endif +#if DEPTH_SHADOWCASTER + , uniform float4 depthRange // x = min, y = max, z = range, w = 1/range +#elif DEPTH_SHADOWRECEIVER + , uniform float4 depthRange0 // x = min, y = max, z = range, w = 1/range + , uniform float4 depthRange1 // x = min, y = max, z = range, w = 1/range + , uniform float4 depthRange2 // x = min, y = max, z = range, w = 1/range +#endif +#if DEPTH_SHADOWRECEIVER + , uniform float4x4 texWorldViewProjMatrix0 + , uniform float4x4 texWorldViewProjMatrix1 + , uniform float4x4 texWorldViewProjMatrix2 +#endif + + ) +{ + VS_OUT outp; + + // project position to the screen + outp.pos = mul(worldViewProj, pos); + +#if !SHADOWCASTER + // Get object space light direction + float3 lightDir = normalize(lightPosition.xyz - (pos.xyz * lightPosition.w).xyz); + outp.col = lightDiffuse.xyz * max(dot(lightDir, normal.xyz), 0.0); +# if FOG + outp.diffuseUV.z = linearFog(outp.pos.z, fogParams.x, fogParams.y); +# endif + +#endif + + // pass through other texcoords exactly as they were received + outp.diffuseUV.xy = uv0.xy; + + +#if DEPTH_SHADOWCASTER + outp.depth = (BIAS + outp.pos.z - depthRange.x) * depthRange.w; +#endif + +#if DEPTH_SHADOWRECEIVER + // Calculate the position of vertex in light space + outp.lightSpacePos0 = mul(texWorldViewProjMatrix0, pos); + outp.lightSpacePos1 = mul(texWorldViewProjMatrix1, pos); + outp.lightSpacePos2 = mul(texWorldViewProjMatrix2, pos); + + // make linear + outp.lightSpacePos0.z = (outp.lightSpacePos0.z - depthRange0.x) * depthRange0.w; + outp.lightSpacePos1.z = (outp.lightSpacePos1.z - depthRange1.x) * depthRange1.w; + outp.lightSpacePos2.z = (outp.lightSpacePos2.z - depthRange2.x) * depthRange2.w; + + // pass cam depth + outp.diffuseUV.z = outp.pos.z; + +#endif + + return outp; +} + + +float4 main_fp( + VS_OUT In, + + uniform sampler2D diffuseMap : register(s0), +#if DEPTH_SHADOWRECEIVER + uniform sampler2D shadowMap0 : register(s1), + uniform sampler2D shadowMap1 : register(s2), + uniform sampler2D shadowMap2 : register(s3), +#endif + + uniform float3 materialAmbient + +#if SHADOWCASTER + , uniform float3 shadowColour +#endif +#if FOG + , uniform float3 fogColour +#endif +#if DEPTH_SHADOWRECEIVER + , uniform float inverseShadowmapSize0 + , uniform float inverseShadowmapSize1 + , uniform float inverseShadowmapSize2 + , uniform float4 pssmSplitPoints +#endif + + ) : COLOR +{ + + // look up the diffuse map layer + float4 texDiffuse = tex2D(diffuseMap, In.diffuseUV.xy); + +#if SHADOWCASTER +# if DEPTH_SHADOWCASTER + // early-out with depth (we still include alpha for those cards that support it) + return float4(In.depth.xxx, 1); +# else + return float4(shadowColour.xyz, texDiffuse.a); +# endif + +#else + // compute the ambient contribution (pulled from the diffuse map) + float3 vAmbient = texDiffuse.xyz * materialAmbient.xyz; + float3 vColor3 = texDiffuse.rgb * In.col.rgb; + +# if DEPTH_SHADOWRECEIVER + float camDepth = In.diffuseUV.z; + float shadow = calcPSSMDepthShadow(shadowMap0, shadowMap1, shadowMap2, + In.lightSpacePos0, In.lightSpacePos1, In.lightSpacePos2, + inverseShadowmapSize0, inverseShadowmapSize1, inverseShadowmapSize2, + pssmSplitPoints, camDepth); + vColor3 *= shadow; + /* + vAmbient = float3(0,0,0); + vColor3 = calcPSSMDebugShadow(shadowMap0, shadowMap1, shadowMap2, + In.lightSpacePos0, In.lightSpacePos1, In.lightSpacePos2, + inverseShadowmapSize0, inverseShadowmapSize1, inverseShadowmapSize2, + pssmSplitPoints, camDepth); + */ +# endif + + float4 vColor; + vColor = float4(vColor3 + vAmbient, texDiffuse.a); + +# if FOG + // if fog is active, interpolate between the unfogged color and the fog color + // based on vertex shader fog value + vColor.rgb = lerp(vColor.rgb, fogColour, In.diffuseUV.z).rgb; +# endif + + return vColor; +#endif + +} + + diff --git a/res/dist/media/materials/programs/depthshadowobjectFp.glsles b/res/dist/media/materials/programs/depthshadowobjectFp.glsles new file mode 100644 index 00000000000..6f1b48d4c3c --- /dev/null +++ b/res/dist/media/materials/programs/depthshadowobjectFp.glsles @@ -0,0 +1,183 @@ +/* Copyright Torus Knot Software Ltd 2012 + +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. +*/ +#include "shadows.cg" + +#define BIAS 0 + +struct VS_OUT +{ + float4 pos : POSITION; + float3 diffuseUV : TEXCOORD0; // xy = UV, z = fog/depth +#if !SHADOWCASTER + float3 col : COLOR; +#endif +#if DEPTH_SHADOWCASTER + float depth : TEXCOORD1; +#endif +#if DEPTH_SHADOWRECEIVER + float4 lightSpacePos0 : TEXCOORD2; + float4 lightSpacePos1 : TEXCOORD3; + float4 lightSpacePos2 : TEXCOORD4; +#endif +}; + +VS_OUT main_vp( + float4 pos : POSITION, + float3 normal : NORMAL, + float4 uv0 : TEXCOORD0, + + uniform float4x4 worldViewProj, + uniform float4 lightPosition, + uniform float3 lightDiffuse +#if FOG + , uniform float2 fogParams // x = fog start, y = fog distance +#endif +#if DEPTH_SHADOWCASTER + , uniform float4 depthRange // x = min, y = max, z = range, w = 1/range +#elif DEPTH_SHADOWRECEIVER + , uniform float4 depthRange0 // x = min, y = max, z = range, w = 1/range + , uniform float4 depthRange1 // x = min, y = max, z = range, w = 1/range + , uniform float4 depthRange2 // x = min, y = max, z = range, w = 1/range +#endif +#if DEPTH_SHADOWRECEIVER + , uniform float4x4 texWorldViewProjMatrix0 + , uniform float4x4 texWorldViewProjMatrix1 + , uniform float4x4 texWorldViewProjMatrix2 +#endif + + ) +{ + VS_OUT outp; + + // project position to the screen + outp.pos = mul(worldViewProj, pos); + +#if !SHADOWCASTER + // Get object space light direction + float3 lightDir = normalize(lightPosition.xyz - (pos.xyz * lightPosition.w).xyz); + outp.col = lightDiffuse.xyz * max(dot(lightDir, normal.xyz), 0.0); +# if FOG + outp.diffuseUV.z = linearFog(outp.pos.z, fogParams.x, fogParams.y); +# endif + +#endif + + // pass through other texcoords exactly as they were received + outp.diffuseUV.xy = uv0.xy; + + +#if DEPTH_SHADOWCASTER + outp.depth = (BIAS + outp.pos.z - depthRange.x) * depthRange.w; +#endif + +#if DEPTH_SHADOWRECEIVER + // Calculate the position of vertex in light space + outp.lightSpacePos0 = mul(texWorldViewProjMatrix0, pos); + outp.lightSpacePos1 = mul(texWorldViewProjMatrix1, pos); + outp.lightSpacePos2 = mul(texWorldViewProjMatrix2, pos); + + // make linear + outp.lightSpacePos0.z = (outp.lightSpacePos0.z - depthRange0.x) * depthRange0.w; + outp.lightSpacePos1.z = (outp.lightSpacePos1.z - depthRange1.x) * depthRange1.w; + outp.lightSpacePos2.z = (outp.lightSpacePos2.z - depthRange2.x) * depthRange2.w; + + // pass cam depth + outp.diffuseUV.z = outp.pos.z; + +#endif + + return outp; +} + + +float4 main_fp( + VS_OUT In, + + uniform sampler2D diffuseMap : register(s0), +#if DEPTH_SHADOWRECEIVER + uniform sampler2D shadowMap0 : register(s1), + uniform sampler2D shadowMap1 : register(s2), + uniform sampler2D shadowMap2 : register(s3), +#endif + + uniform float3 materialAmbient + +#if SHADOWCASTER + , uniform float3 shadowColour +#endif +#if FOG + , uniform float3 fogColour +#endif +#if DEPTH_SHADOWRECEIVER + , uniform float inverseShadowmapSize0 + , uniform float inverseShadowmapSize1 + , uniform float inverseShadowmapSize2 + , uniform float4 pssmSplitPoints +#endif + + ) : COLOR +{ + + // look up the diffuse map layer + float4 texDiffuse = tex2D(diffuseMap, In.diffuseUV.xy); + +#if SHADOWCASTER +# if DEPTH_SHADOWCASTER + // early-out with depth (we still include alpha for those cards that support it) + return float4(In.depth.xxx, 1); +# else + return float4(shadowColour.xyz, texDiffuse.a); +# endif + +#else + // compute the ambient contribution (pulled from the diffuse map) + float3 vAmbient = texDiffuse.xyz * materialAmbient.xyz; + float3 vColor3 = texDiffuse.rgb * In.col.rgb; + +# if DEPTH_SHADOWRECEIVER + float camDepth = In.diffuseUV.z; + float shadow = calcPSSMDepthShadow(shadowMap0, shadowMap1, shadowMap2, + In.lightSpacePos0, In.lightSpacePos1, In.lightSpacePos2, + inverseShadowmapSize0, inverseShadowmapSize1, inverseShadowmapSize2, + pssmSplitPoints, camDepth); + vColor3 *= shadow; + /* + vAmbient = float3(0,0,0); + vColor3 = calcPSSMDebugShadow(shadowMap0, shadowMap1, shadowMap2, + In.lightSpacePos0, In.lightSpacePos1, In.lightSpacePos2, + inverseShadowmapSize0, inverseShadowmapSize1, inverseShadowmapSize2, + pssmSplitPoints, camDepth); + */ +# endif + + float4 vColor; + vColor = float4(vColor3 + vAmbient, texDiffuse.a); + +# if FOG + // if fog is active, interpolate between the unfogged color and the fog color + // based on vertex shader fog value + vColor.rgb = mix(vColor.rgb, fogColour, In.diffuseUV.z).rgb; +# endif + + return vColor; +#endif + +} diff --git a/res/dist/media/materials/programs/depthshadowobjectVp.glsles b/res/dist/media/materials/programs/depthshadowobjectVp.glsles new file mode 100644 index 00000000000..6f1b48d4c3c --- /dev/null +++ b/res/dist/media/materials/programs/depthshadowobjectVp.glsles @@ -0,0 +1,183 @@ +/* Copyright Torus Knot Software Ltd 2012 + +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. +*/ +#include "shadows.cg" + +#define BIAS 0 + +struct VS_OUT +{ + float4 pos : POSITION; + float3 diffuseUV : TEXCOORD0; // xy = UV, z = fog/depth +#if !SHADOWCASTER + float3 col : COLOR; +#endif +#if DEPTH_SHADOWCASTER + float depth : TEXCOORD1; +#endif +#if DEPTH_SHADOWRECEIVER + float4 lightSpacePos0 : TEXCOORD2; + float4 lightSpacePos1 : TEXCOORD3; + float4 lightSpacePos2 : TEXCOORD4; +#endif +}; + +VS_OUT main_vp( + float4 pos : POSITION, + float3 normal : NORMAL, + float4 uv0 : TEXCOORD0, + + uniform float4x4 worldViewProj, + uniform float4 lightPosition, + uniform float3 lightDiffuse +#if FOG + , uniform float2 fogParams // x = fog start, y = fog distance +#endif +#if DEPTH_SHADOWCASTER + , uniform float4 depthRange // x = min, y = max, z = range, w = 1/range +#elif DEPTH_SHADOWRECEIVER + , uniform float4 depthRange0 // x = min, y = max, z = range, w = 1/range + , uniform float4 depthRange1 // x = min, y = max, z = range, w = 1/range + , uniform float4 depthRange2 // x = min, y = max, z = range, w = 1/range +#endif +#if DEPTH_SHADOWRECEIVER + , uniform float4x4 texWorldViewProjMatrix0 + , uniform float4x4 texWorldViewProjMatrix1 + , uniform float4x4 texWorldViewProjMatrix2 +#endif + + ) +{ + VS_OUT outp; + + // project position to the screen + outp.pos = mul(worldViewProj, pos); + +#if !SHADOWCASTER + // Get object space light direction + float3 lightDir = normalize(lightPosition.xyz - (pos.xyz * lightPosition.w).xyz); + outp.col = lightDiffuse.xyz * max(dot(lightDir, normal.xyz), 0.0); +# if FOG + outp.diffuseUV.z = linearFog(outp.pos.z, fogParams.x, fogParams.y); +# endif + +#endif + + // pass through other texcoords exactly as they were received + outp.diffuseUV.xy = uv0.xy; + + +#if DEPTH_SHADOWCASTER + outp.depth = (BIAS + outp.pos.z - depthRange.x) * depthRange.w; +#endif + +#if DEPTH_SHADOWRECEIVER + // Calculate the position of vertex in light space + outp.lightSpacePos0 = mul(texWorldViewProjMatrix0, pos); + outp.lightSpacePos1 = mul(texWorldViewProjMatrix1, pos); + outp.lightSpacePos2 = mul(texWorldViewProjMatrix2, pos); + + // make linear + outp.lightSpacePos0.z = (outp.lightSpacePos0.z - depthRange0.x) * depthRange0.w; + outp.lightSpacePos1.z = (outp.lightSpacePos1.z - depthRange1.x) * depthRange1.w; + outp.lightSpacePos2.z = (outp.lightSpacePos2.z - depthRange2.x) * depthRange2.w; + + // pass cam depth + outp.diffuseUV.z = outp.pos.z; + +#endif + + return outp; +} + + +float4 main_fp( + VS_OUT In, + + uniform sampler2D diffuseMap : register(s0), +#if DEPTH_SHADOWRECEIVER + uniform sampler2D shadowMap0 : register(s1), + uniform sampler2D shadowMap1 : register(s2), + uniform sampler2D shadowMap2 : register(s3), +#endif + + uniform float3 materialAmbient + +#if SHADOWCASTER + , uniform float3 shadowColour +#endif +#if FOG + , uniform float3 fogColour +#endif +#if DEPTH_SHADOWRECEIVER + , uniform float inverseShadowmapSize0 + , uniform float inverseShadowmapSize1 + , uniform float inverseShadowmapSize2 + , uniform float4 pssmSplitPoints +#endif + + ) : COLOR +{ + + // look up the diffuse map layer + float4 texDiffuse = tex2D(diffuseMap, In.diffuseUV.xy); + +#if SHADOWCASTER +# if DEPTH_SHADOWCASTER + // early-out with depth (we still include alpha for those cards that support it) + return float4(In.depth.xxx, 1); +# else + return float4(shadowColour.xyz, texDiffuse.a); +# endif + +#else + // compute the ambient contribution (pulled from the diffuse map) + float3 vAmbient = texDiffuse.xyz * materialAmbient.xyz; + float3 vColor3 = texDiffuse.rgb * In.col.rgb; + +# if DEPTH_SHADOWRECEIVER + float camDepth = In.diffuseUV.z; + float shadow = calcPSSMDepthShadow(shadowMap0, shadowMap1, shadowMap2, + In.lightSpacePos0, In.lightSpacePos1, In.lightSpacePos2, + inverseShadowmapSize0, inverseShadowmapSize1, inverseShadowmapSize2, + pssmSplitPoints, camDepth); + vColor3 *= shadow; + /* + vAmbient = float3(0,0,0); + vColor3 = calcPSSMDebugShadow(shadowMap0, shadowMap1, shadowMap2, + In.lightSpacePos0, In.lightSpacePos1, In.lightSpacePos2, + inverseShadowmapSize0, inverseShadowmapSize1, inverseShadowmapSize2, + pssmSplitPoints, camDepth); + */ +# endif + + float4 vColor; + vColor = float4(vColor3 + vAmbient, texDiffuse.a); + +# if FOG + // if fog is active, interpolate between the unfogged color and the fog color + // based on vertex shader fog value + vColor.rgb = mix(vColor.rgb, fogColour, In.diffuseUV.z).rgb; +# endif + + return vColor; +#endif + +} diff --git a/res/dist/media/materials/programs/hdr.cg b/res/dist/media/materials/programs/hdr.cg new file mode 100644 index 00000000000..a12237c92fc --- /dev/null +++ b/res/dist/media/materials/programs/hdr.cg @@ -0,0 +1,25 @@ +void morningskybox_fp ( + float2 uv : TEXCOORD0, + out float4 colour : COLOR, + + uniform sampler2D tex : register(s0) ) +{ + colour = tex2D(tex, uv); + + // blow out the light a bit + colour *= 1.7; +} +void morningcubemap_fp ( + float3 uv : TEXCOORD0, + out float4 colour : COLOR, + + uniform samplerCUBE tex : register(s0) ) +{ + colour = texCUBE(tex, uv); + + // blow out the light a bit + colour *= 1.7; +} + + + diff --git a/res/dist/media/materials/programs/hdr.hlsl b/res/dist/media/materials/programs/hdr.hlsl new file mode 100644 index 00000000000..c27e5a072a4 --- /dev/null +++ b/res/dist/media/materials/programs/hdr.hlsl @@ -0,0 +1,165 @@ +#include + +/* Downsample a 2x2 area and convert to greyscale +*/ +float4 downscale2x2Luminence( + float2 uv : TEXCOORD0, + uniform float2 texelSize, // depends on size of source texture + uniform sampler2D inRTT : register(s0) + ) : COLOR +{ + + float4 accum = float4(0.0f, 0.0f, 0.0f, 0.0f); + + float2 texOffset[4] = { + -0.5, -0.5, + -0.5, 0.5, + 0.5, -0.5, + 0.5, 0.5 }; + + for( int i = 0; i < 4; i++ ) + { + // Get colour from source + accum += tex2D(inRTT, uv + texelSize * texOffset[i]); + } + + // Adjust the accumulated amount by lum factor + // Cannot use float3's here because it generates dependent texture errors because of swizzle + float lum = dot(accum, LUMINENCE_FACTOR); + // take average of 4 samples + lum *= 0.25; + return lum; + +} + +/* Downsample a 3x3 area + * This shader is used multiple times on different source sizes, so texel size has to be configurable +*/ +float4 downscale3x3( + float2 uv : TEXCOORD0, + uniform float2 texelSize, // depends on size of source texture + uniform sampler2D inRTT : register(s0) + ) : COLOR +{ + + float4 accum = float4(0.0f, 0.0f, 0.0f, 0.0f); + + float2 texOffset[9] = { + -1.0, -1.0, + 0.0, -1.0, + 1.0, -1.0, + -1.0, 0.0, + 0.0, 0.0, + 1.0, 0.0, + -1.0, 1.0, + 0.0, 1.0, + 1.0, 1.0 + }; + + for( int i = 0; i < 9; i++ ) + { + // Get colour from source + accum += tex2D(inRTT, uv + texelSize * texOffset[i]); + } + + // take average of 9 samples + accum *= 0.1111111111111111; + return accum; + +} + +/* Downsample a 3x3 area from main RTT and perform a brightness pass +*/ +float4 downscale3x3brightpass( + float2 uv : TEXCOORD0, + uniform float2 texelSize, // depends on size of source texture + uniform sampler2D inRTT : register(s0), + uniform sampler2D inLum : register(s1) + ) : COLOR +{ + + float4 accum = float4(0.0f, 0.0f, 0.0f, 0.0f); + + float2 texOffset[9] = { + -1.0, -1.0, + 0.0, -1.0, + 1.0, -1.0, + -1.0, 0.0, + 0.0, 0.0, + 1.0, 0.0, + -1.0, 1.0, + 0.0, 1.0, + 1.0, 1.0 + }; + + for( int i = 0; i < 9; i++ ) + { + // Get colour from source + accum += tex2D(inRTT, uv + texelSize * texOffset[i]); + } + + // take average of 9 samples + accum *= 0.1111111111111111; + + // Reduce bright and clamp + accum = max(float4(0.0f, 0.0f, 0.0f, 1.0f), accum - BRIGHT_LIMITER); + + // Sample the luminence texture + float4 lum = tex2D(inLum, float2(0.5f, 0.5f)); + + // Tone map result + return toneMap(accum, lum.r); + +} + +/* Gaussian bloom, requires offsets and weights to be provided externally +*/ +float4 bloom( + float2 uv : TEXCOORD0, + uniform float2 sampleOffsets[15], + uniform float4 sampleWeights[15], + uniform sampler2D inRTT : register(s0) + ) : COLOR +{ + float4 accum = float4(0.0f, 0.0f, 0.0f, 1.0f); + float2 sampleUV; + + for( int i = 0; i < 15; i++ ) + { + // Sample from adjacent points, 7 each side and central + sampleUV = uv + sampleOffsets[i]; + accum += sampleWeights[i] * tex2D(inRTT, sampleUV); + } + + return accum; + +} + + +/* Final scene composition, with tone mapping +*/ +float4 finalToneMapping( + float2 uv : TEXCOORD0, + uniform sampler2D inRTT : register(s0), + uniform sampler2D inBloom : register(s1), + uniform sampler2D inLum : register(s2) + ) : COLOR +{ + // Get main scene colour + float4 sceneCol = tex2D(inRTT, uv); + + // Get luminence value + float4 lum = tex2D(inLum, float2(0.5f, 0.5f)); + + // tone map this + float4 toneMappedSceneCol = toneMap(sceneCol, lum.r); + + // Get bloom colour + float4 bloom = tex2D(inBloom, uv); + + // Add scene & bloom + return float4(toneMappedSceneCol.rgb + bloom.rgb, 1.0f); + +} + + diff --git a/res/dist/media/materials/programs/hdrFp.glsles b/res/dist/media/materials/programs/hdrFp.glsles new file mode 100644 index 00000000000..854dd00442c --- /dev/null +++ b/res/dist/media/materials/programs/hdrFp.glsles @@ -0,0 +1,15 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D tex; +varying vec4 ambientUV; + +void main () +{ + gl_FragColor = vec4(texture2D(tex, ambientUV.xy)); + + // Blow out the light a bit + gl_FragColor *= 1.7; +} diff --git a/res/dist/media/materials/programs/hdr_bloom.glsl b/res/dist/media/materials/programs/hdr_bloom.glsl new file mode 100644 index 00000000000..d69926668c8 --- /dev/null +++ b/res/dist/media/materials/programs/hdr_bloom.glsl @@ -0,0 +1,22 @@ +uniform sampler2D inRTT; + +uniform vec4 sampleOffsets[15]; +uniform vec4 sampleWeights[15]; + +varying vec2 uv; + +void main(void) +{ + vec4 accum = vec4(0.0, 0.0, 0.0, 1.0); + vec2 sampleUV; + + for( int i = 0; i < 15; i++ ) + { + // Sample from adjacent points, 7 each side and central + sampleUV = uv + sampleOffsets[i].xy; + accum += sampleWeights[i] * texture2D(inRTT, sampleUV); + } + + gl_FragColor = accum; + +} diff --git a/res/dist/media/materials/programs/hdr_bloom.glsles b/res/dist/media/materials/programs/hdr_bloom.glsles new file mode 100644 index 00000000000..27b0e934705 --- /dev/null +++ b/res/dist/media/materials/programs/hdr_bloom.glsles @@ -0,0 +1,25 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D inRTT; + +uniform vec4 sampleOffsets[15]; +uniform vec4 sampleWeights[15]; + +varying vec2 uv; + +void main(void) +{ + vec4 accum = vec4(0.0, 0.0, 0.0, 1.0); + vec2 sampleUV; + + for( int i = 0; i < 15; i++ ) + { + // Sample from adjacent points, 7 each side and central + sampleUV = uv + sampleOffsets[i].xy; + accum += sampleWeights[i] * texture2D(inRTT, sampleUV); + } + + gl_FragColor = accum; +} diff --git a/res/dist/media/materials/programs/hdr_downscale2x2luminence.glsl b/res/dist/media/materials/programs/hdr_downscale2x2luminence.glsl new file mode 100644 index 00000000000..976a726bf1b --- /dev/null +++ b/res/dist/media/materials/programs/hdr_downscale2x2luminence.glsl @@ -0,0 +1,24 @@ +uniform sampler2D inRTT; +uniform vec2 texelSize; + +varying vec2 uv; + +void main(void) +{ + + vec4 accum = vec4(0.0, 0.0, 0.0, 0.0); + vec4 LUMINENCE_FACTOR = vec4(0.27, 0.67, 0.06, 0.0); + + // Get colour from source + accum += texture2D(inRTT, uv + texelSize * vec2(-0.5, -0.5)); + accum += texture2D(inRTT, uv + texelSize * vec2(-0.5, 0.5)); + accum += texture2D(inRTT, uv + texelSize * vec2(0.5, 0.5)); + accum += texture2D(inRTT, uv + texelSize * vec2(0.5, -0.5)); + + // Adjust the accumulated amount by lum factor + float lum = dot(accum, LUMINENCE_FACTOR); + // take average of 4 samples + lum *= 0.25; + gl_FragColor = vec4(lum, lum, lum, 1.0); + +} diff --git a/res/dist/media/materials/programs/hdr_downscale2x2luminence.glsles b/res/dist/media/materials/programs/hdr_downscale2x2luminence.glsles new file mode 100644 index 00000000000..3f7960b3228 --- /dev/null +++ b/res/dist/media/materials/programs/hdr_downscale2x2luminence.glsles @@ -0,0 +1,26 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D inRTT; +uniform vec2 texelSize; + +varying vec2 uv; + +void main() +{ + vec4 accum = vec4(0.0, 0.0, 0.0, 0.0); + vec4 LUMINENCE_FACTOR = vec4(0.27, 0.67, 0.06, 0.0); + + // Get colour from source + accum += texture2D(inRTT, uv + texelSize * vec2(-0.5, -0.5)); + accum += texture2D(inRTT, uv + texelSize * vec2(-0.5, 0.5)); + accum += texture2D(inRTT, uv + texelSize * vec2(0.5, 0.5)); + accum += texture2D(inRTT, uv + texelSize * vec2(0.5, -0.5)); + + // Adjust the accumulated amount by lum factor + float lum = dot(accum, LUMINENCE_FACTOR); + // take average of 4 samples + lum *= 0.25; + gl_FragColor = vec4(lum, lum, lum, 1.0); +} diff --git a/res/dist/media/materials/programs/hdr_downscale3x3.glsl b/res/dist/media/materials/programs/hdr_downscale3x3.glsl new file mode 100644 index 00000000000..2f6a999c850 --- /dev/null +++ b/res/dist/media/materials/programs/hdr_downscale3x3.glsl @@ -0,0 +1,26 @@ +uniform sampler2D inRTT; +uniform vec2 texelSize; + +varying vec2 uv; + +void main(void) +{ + vec4 accum = vec4(0.0, 0.0, 0.0, 0.0); + + // Get colour from source + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 1.0)); + + // take average of 9 samples + accum *= 0.1111111111111111; + + gl_FragColor = accum; + +} diff --git a/res/dist/media/materials/programs/hdr_downscale3x3.glsles b/res/dist/media/materials/programs/hdr_downscale3x3.glsles new file mode 100644 index 00000000000..a54a04f4562 --- /dev/null +++ b/res/dist/media/materials/programs/hdr_downscale3x3.glsles @@ -0,0 +1,30 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D inRTT; +uniform vec2 texelSize; + +varying vec2 uv; + +void main(void) +{ + vec4 accum = vec4(0.0, 0.0, 0.0, 0.0); + + // Get colour from source + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 1.0)); + + // take average of 9 samples + accum *= 0.1111111111111111; + + gl_FragColor = accum; + +} diff --git a/res/dist/media/materials/programs/hdr_downscale3x3brightpass.glsl b/res/dist/media/materials/programs/hdr_downscale3x3brightpass.glsl new file mode 100644 index 00000000000..83d4afbae1b --- /dev/null +++ b/res/dist/media/materials/programs/hdr_downscale3x3brightpass.glsl @@ -0,0 +1,37 @@ +uniform sampler2D inRTT; +uniform sampler2D inLum; +uniform vec2 texelSize; + +varying vec2 uv; +const vec4 BRIGHT_LIMITER = vec4(0.6, 0.6, 0.6, 0.0); + +// declare external function +vec4 toneMap(in vec4 inColour, in float lum); + +void main(void) +{ + vec4 accum = vec4(0.0, 0.0, 0.0, 0.0); + + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 1.0)); + + // take average of 9 samples + accum *= 0.1111111111111111; + + // Reduce bright and clamp + accum = max(vec4(0.0, 0.0, 0.0, 1.0), accum - BRIGHT_LIMITER); + + // Sample the luminence texture + vec4 lum = texture2D(inLum, vec2(0.5, 0.5)); + + // Tone map result + gl_FragColor = toneMap(accum, lum.r); + +} diff --git a/res/dist/media/materials/programs/hdr_downscale3x3brightpass.glsles b/res/dist/media/materials/programs/hdr_downscale3x3brightpass.glsles new file mode 100644 index 00000000000..b624391e0ec --- /dev/null +++ b/res/dist/media/materials/programs/hdr_downscale3x3brightpass.glsles @@ -0,0 +1,64 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D inRTT; +uniform sampler2D inLum; +uniform vec2 texelSize; + +varying vec2 uv; +const vec4 BRIGHT_LIMITER = vec4(0.6, 0.6, 0.6, 0.0); + +const float MIDDLE_GREY = 0.72; +const float FUDGE = 0.001; +const float L_WHITE = 1.5; + +/** Tone mapping function +@note Only affects rgb, not a +@param inColour The HDR colour +@param lum The scene lumninence +@returns Tone mapped colour +*/ +vec4 toneMap(in vec4 inColour, in float lum) +{ + // From Reinhard et al + // "Photographic Tone Reproduction for Digital Images" + + // Initial luminence scaling (equation 2) + inColour.rgb *= MIDDLE_GREY / (FUDGE + lum); + + // Control white out (equation 4 nom) + inColour.rgb *= (1.0 + inColour.rgb / L_WHITE); + + // Final mapping (equation 4 denom) + inColour.rgb /= (1.0 + inColour.rgb); + + return inColour; +} + +void main(void) +{ + vec4 accum = vec4(0.0, 0.0, 0.0, 0.0); + + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, -1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 0.0)); + accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 1.0)); + accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 1.0)); + + // take average of 9 samples + accum *= 0.1111111111111111; + + // Reduce bright and clamp + accum = max(vec4(0.0, 0.0, 0.0, 1.0), accum - BRIGHT_LIMITER); + + // Sample the luminence texture + vec4 lum = texture2D(inLum, vec2(0.5, 0.5)); + + // Tone map result + gl_FragColor = toneMap(accum, lum.r); +} diff --git a/res/dist/media/materials/programs/hdr_finalToneMapping.glsl b/res/dist/media/materials/programs/hdr_finalToneMapping.glsl new file mode 100644 index 00000000000..94c1b3e6b3f --- /dev/null +++ b/res/dist/media/materials/programs/hdr_finalToneMapping.glsl @@ -0,0 +1,28 @@ +uniform sampler2D inRTT; +uniform sampler2D inBloom; +uniform sampler2D inLum; + +varying vec2 uv; + +// declare external function +vec4 toneMap(in vec4 inColour, in float lum); + +void main(void) +{ + // Get main scene colour + vec4 sceneCol = texture2D(inRTT, uv); + + // Get luminence value + vec4 lum = texture2D(inLum, vec2(0.5, 0.5)); + + // tone map this + vec4 toneMappedSceneCol = toneMap(sceneCol, lum.r); + + // Get bloom colour + vec4 bloom = texture2D(inBloom, uv); + + // Add scene & bloom + gl_FragColor = vec4(toneMappedSceneCol.rgb + bloom.rgb, 1.0); + +} + diff --git a/res/dist/media/materials/programs/hdr_finalToneMapping.glsles b/res/dist/media/materials/programs/hdr_finalToneMapping.glsles new file mode 100644 index 00000000000..13a25a7e9c2 --- /dev/null +++ b/res/dist/media/materials/programs/hdr_finalToneMapping.glsles @@ -0,0 +1,54 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D inRTT; +uniform sampler2D inBloom; +uniform sampler2D inLum; + +varying vec2 uv; + +const float MIDDLE_GREY = 0.72; +const float FUDGE = 0.001; +const float L_WHITE = 1.5; + +/** Tone mapping function +@note Only affects rgb, not a +@param inColour The HDR colour +@param lum The scene lumninence +@returns Tone mapped colour +*/ +vec4 toneMap(in vec4 inColour, in float lum) +{ + // From Reinhard et al + // "Photographic Tone Reproduction for Digital Images" + + // Initial luminence scaling (equation 2) + inColour.rgb *= MIDDLE_GREY / (FUDGE + lum); + + // Control white out (equation 4 nom) + inColour.rgb *= (1.0 + inColour.rgb / L_WHITE); + + // Final mapping (equation 4 denom) + inColour.rgb /= (1.0 + inColour.rgb); + + return inColour; +} + +void main(void) +{ + // Get main scene colour + vec4 sceneCol = texture2D(inRTT, uv); + + // Get luminence value + vec4 lum = texture2D(inLum, vec2(0.5, 0.5)); + + // tone map this + vec4 toneMappedSceneCol = toneMap(sceneCol, lum.r); + + // Get bloom colour + vec4 bloom = texture2D(inBloom, uv); + + // Add scene & bloom + gl_FragColor = vec4(toneMappedSceneCol.rgb + bloom.rgb, 1.0); +} diff --git a/res/dist/media/materials/programs/hdr_tonemap_util.glsl b/res/dist/media/materials/programs/hdr_tonemap_util.glsl new file mode 100644 index 00000000000..14c58fb121d --- /dev/null +++ b/res/dist/media/materials/programs/hdr_tonemap_util.glsl @@ -0,0 +1,29 @@ +const float MIDDLE_GREY = 0.72; +const float FUDGE = 0.001; +const float L_WHITE = 1.5; + +/** Tone mapping function +@note Only affects rgb, not a +@param inColour The HDR colour +@param lum The scene lumninence +@returns Tone mapped colour +*/ +vec4 toneMap(in vec4 inColour, in float lum) +{ + // From Reinhard et al + // "Photographic Tone Reproduction for Digital Images" + + // Initial luminence scaling (equation 2) + inColour.rgb *= MIDDLE_GREY / (FUDGE + lum); + + // Control white out (equation 4 nom) + inColour.rgb *= (1.0 + inColour.rgb / L_WHITE); + + // Final mapping (equation 4 denom) + inColour.rgb /= (1.0 + inColour.rgb); + + return inColour; + +} + + diff --git a/res/dist/media/materials/programs/hdrutils.hlsl b/res/dist/media/materials/programs/hdrutils.hlsl new file mode 100644 index 00000000000..08f899f89df --- /dev/null +++ b/res/dist/media/materials/programs/hdrutils.hlsl @@ -0,0 +1,65 @@ +// RGBE mode utilities +// RGB each carry a mantissa, A carries a shared exponent +// The exponent is calculated based on the largest colour channel + + +float3 decodeRGBE8(in float4 rgbe) +{ + // get exponent (-128 since it can be +ve or -ve) + float exp = rgbe.a * 255 - 128; + + // expand out the rgb value + return rgbe.rgb * exp2(exp); +} + +float4 encodeRGBE8(in float3 rgb) +{ + float4 ret; + + // What is the largest colour channel? + float highVal = max(rgb.r, max(rgb.g, rgb.b)); + + // Take the logarithm, clamp it to a whole value + float exp = ceil(log2(highVal)); + + // Divide the components by the shared exponent + ret.rgb = rgb / exp2(exp); + + // Store the shared exponent in the alpha channel + ret.a = (exp + 128) / 255; + + return ret; +} + + +static const float4 LUMINENCE_FACTOR = float4(0.27f, 0.67f, 0.06f, 0.0f); +static const float MIDDLE_GREY = 0.72f; +static const float FUDGE = 0.001f; +static const float L_WHITE = 1.5f; +static const float4 BRIGHT_LIMITER = float4(0.6f, 0.6f, 0.6f, 0.0f); + + +/** Tone mapping function +@note Only affects rgb, not a +@param inColour The HDR colour +@param lum The scene lumninence +@returns Tone mapped colour +*/ +float4 toneMap(float4 inColour, float lum) +{ + // From Reinhard et al + // "Photographic Tone Reproduction for Digital Images" + + // Initial luminence scaling (equation 2) + inColour.rgb *= MIDDLE_GREY / (FUDGE + lum); + + // Control white out (equation 4 nom) + inColour.rgb *= (1.0f + inColour / L_WHITE); + + // Final mapping (equation 4 denom) + inColour.rgb /= (1.0f + inColour); + + return inColour; + +} + diff --git a/res/dist/media/materials/programs/instancing.cg b/res/dist/media/materials/programs/instancing.cg new file mode 100644 index 00000000000..241f41bebab --- /dev/null +++ b/res/dist/media/materials/programs/instancing.cg @@ -0,0 +1,125 @@ + + +void instancing_vp(uniform float3x4 worldMatrix3x4Array[80], float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float index : TEXCOORD1, + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos, + uniform float4 ambient, + uniform float4 lightDiffuseColour, + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 Color : COLOR ) +{ + // transform by indexed matrix + float4 transformedPos = float4(mul(worldMatrix3x4Array[index], position).xyz, 1.0); + + // view / projection + oPosition = mul(viewProjectionMatrix, transformedPos); + oUv = uv; + + float3 norm = mul((float3x3)worldMatrix3x4Array[index], normal); + + float3 lightDir = normalize( + lightPos.xyz - (transformedPos.xyz * lightPos.w)); + + Color = ambient + saturate(dot(lightDir, norm)) * lightDiffuseColour; + + +} + +/* + Instancing shadow-caster pass +*/ +void instancingCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float index : TEXCOORD1, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 80 bones of float3x4 + uniform float3x4 worldMatrix3x4Array[80], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 transformedPos = float4(mul(worldMatrix3x4Array[index], position).xyz, 1.0); + + // view / projection + oPosition = mul(viewProjectionMatrix, transformedPos); + + colour = ambient; + +} +void crowd_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + float index : TEXCOORD1, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 20 bones of float3x4 + // vs_2_0 only supports 256 params so more than this is not feasible + uniform float4x4 viewProjectionMatrix, + uniform float numBones, + uniform float3x4 worldMatrix3x4Array[80], + uniform float4 lightDiffuseColour, + uniform float4 ambient, + uniform float4 lightPos) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 4; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[index*numBones+blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + oUv = uv; + float3 norm = float3(0,0,0); + for (i = 0; i < 4; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[index*numBones+blendIdx[i]], normal)* blendWgt[i]; + } + float3 lightDir = normalize( + lightPos.xyz - (blendPos.xyz * lightPos.w)); + + colour = ambient + saturate(dot(lightDir, norm)) * lightDiffuseColour; + + +} + +/* + Single-weight-per-vertex hardware skinning, shadow-caster pass +*/ +void crowdCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float blendIdx : BLENDINDICES, + float index : TEXCOORD1, + + 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[80], + uniform float4x4 viewProjectionMatrix, + uniform float numBones, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[index*numBones+blendIdx], position).xyz, 1.0); + + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + colour = ambient; + +} diff --git a/res/dist/media/materials/programs/instancingVp.glsl b/res/dist/media/materials/programs/instancingVp.glsl new file mode 100644 index 00000000000..06a6566540c --- /dev/null +++ b/res/dist/media/materials/programs/instancingVp.glsl @@ -0,0 +1,39 @@ +uniform vec4 worldMatrix3x4Array[240]; +uniform mat4 viewProjectionMatrix; +uniform vec4 lightPos; +uniform vec4 ambient; +uniform vec4 lightDiffuseColour; + +void main() +{ + + // transform by indexed matrix + // perform matrix multiplication manually since no 3x4 matrices + vec3 transformedPos; + vec3 transformedNorm; + int instanceOffset = int(gl_MultiTexCoord1.x) * 3; + for (int row = 0; row < 3; ++row) + { + vec4 matrixRow = worldMatrix3x4Array[instanceOffset + row]; + transformedPos[row] = dot(matrixRow, gl_Vertex); +#if SHADOW_CASTER +#else + transformedNorm[row] = dot(matrixRow.xyz, gl_Normal); +#endif + + } + + // view / projection + gl_Position = viewProjectionMatrix * vec4(transformedPos,1); + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_FrontSecondaryColor = vec4(0); + +#if SHADOW_CASTER + gl_FrontColor = ambient; +#else + vec3 lightDir = normalize( + lightPos.xyz - (transformedPos.xyz * lightPos.w)); + gl_FrontColor = ambient + clamp(dot(lightDir, transformedNorm),0.0,1.0) * lightDiffuseColour; +#endif + +} diff --git a/res/dist/media/materials/programs/instancingVp.glsles b/res/dist/media/materials/programs/instancingVp.glsles new file mode 100644 index 00000000000..aaec002bbc9 --- /dev/null +++ b/res/dist/media/materials/programs/instancingVp.glsles @@ -0,0 +1,51 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform vec4 worldMatrix3x4Array[240]; +uniform mat4 viewProjectionMatrix; +uniform vec4 lightPos; +uniform vec4 ambient; +uniform vec4 lightDiffuseColour; + +attribute vec4 position; +attribute vec3 normal; +attribute vec4 uv0; +attribute vec4 uv1; + +varying vec4 colour; +varying vec4 oUv0; +varying vec4 oUv1; + +void main() +{ + + // transform by indexed matrix + // perform matrix multiplication manually since no 3x4 matrices + vec3 transformedPos; + vec3 transformedNorm; + int instanceOffset = int(uv1.x) * 3; + for (int row = 0; row < 3; ++row) + { + vec4 matrixRow = worldMatrix3x4Array[instanceOffset + row]; + transformedPos[row] = dot(matrixRow, position); +#if SHADOW_CASTER +#else + transformedNorm[row] = dot(matrixRow.xyz, normal); +#endif + } + + // view / projection + gl_Position = viewProjectionMatrix * vec4(transformedPos, 1.0); + colour = vec4(0); + +#if SHADOW_CASTER + colour = ambient; +#else + vec3 lightDir = normalize( + lightPos.xyz - (transformedPos.xyz * lightPos.w)); + colour = ambient + clamp(dot(lightDir, transformedNorm),0.0,1.0) * lightDiffuseColour; +#endif + +} diff --git a/res/dist/media/materials/programs/isosurf.cg b/res/dist/media/materials/programs/isosurf.cg new file mode 100644 index 00000000000..bcb057c9af0 --- /dev/null +++ b/res/dist/media/materials/programs/isosurf.cg @@ -0,0 +1,155 @@ +// Ogre port of Nvidia's IsoSurf.cg file +// Modified code follows. See http://developer.download.nvidia.com/SDK/10/opengl/samples.html for original +// +// Cg port of Yury Uralsky's metaball FX shader +// +// Authors: Simon Green and Yury Urlasky +// Email: sdkfeedback@nvidia.com +// +// Copyright (c) NVIDIA Corporation. All rights reserved. +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct SampleData +{ + float4 Pos : POSITION; + float3 N : TEXCOORD0; + float2 Field : TEXCOORD1; + float4 Color : COLOR0; +}; + +struct SurfaceVertex +{ + float4 Pos : POSITION; + float3 N : TEXCOORD0; +}; + +uniform int Num_Metaballs = 2; +uniform float4 Metaballs[] = { + { -0.5, 0, 0, 0.2 }, + { 0.6, 0, 0, 0.4 }, +}; + +// Size of the sampling grid +uniform int3 SizeMask = { 63, 63, 63 }; +uniform int3 SizeShift = { 0, 6, 12 }; + +uniform float IsoValue = 1.0; + +// Metaball function +// Returns metaball function value in .w and its gradient in .xyz + +float4 Metaball(float3 Pos, float3 Center, float RadiusSq) +{ + float epsilon = 0.001; + + float3 Dist = Pos - Center; + float InvDistSq = 1 / (dot(Dist, Dist) + epsilon); + + float4 o; + o.xyz = -2 * RadiusSq * InvDistSq * InvDistSq * Dist; + o.w = RadiusSq * InvDistSq; + return o; +} + +// Vertex shader +SampleData mainVS(float4 pos : POSITION, + uniform float4x4 WorldViewProj, + uniform float4x4 origWorldViewIT) +{ + SampleData o; + + // Sum up contributions from all metaballs + float4 Field = 0; + for (int i = 0; i<2; i++) + { + Field += Metaball(pos.xyz, Metaballs[i].xyz, Metaballs[i].w); + } + + float3x3 WorldViewIT = { origWorldViewIT[0].xyz, origWorldViewIT[1].xyz, origWorldViewIT[2].xyz }; + + // Transform position and normals + o.Pos = mul(WorldViewProj, pos); + o.N = mul(WorldViewIT, Field.xyz); // we want normals in world space + o.Field.x = Field.w; + + // Generate in-out flags + o.Field.y = (Field.w < IsoValue) ? 1 : 0; + + o.Color = (Field*0.5+0.5) * (Field.w / 10.0); + return o; +} + + + +// Estimate where isosurface intersects grid edge with endpoints v0, v1 +void CalcIntersection(float4 Pos0, + float3 N0, + float2 Field0, + float4 Pos1, + float3 N1, + float2 Field1) +{ + float t = (IsoValue - Field0.x) / (Field1.x - Field0.x); + if ((Field0.x < IsoValue) && (Field1.x > Field0.x)) + { + if (t > 0 && t < 1) + { + float4 Pos = lerp(Pos0, Pos1, t); + float3 N = lerp(N0, N1, t); + emitVertex(Pos : POSITION, N : TEXCOORD0); + } + } +} + +// Geometry shader +// input: line with adjacency (tetrahedron) +// outputs: zero, one or two triangles depending if isosurface intersects tetrahedron +LINE_ADJ +TRIANGLE_OUT +void mainGS( + AttribArray Pos : POSITION, + AttribArray N : TEXCOORD0, + AttribArray Field : TEXCOORD1 + ) +{ + // construct index for this tetrahedron + unsigned int index = (int(Field[0].y) << 3) | + (int(Field[1].y) << 2) | + (int(Field[2].y) << 1) | + int(Field[3].y); + + // don't bother if all vertices out or all vertices inside isosurface + if (index > 0 && index < 15) + { + //Uber-compressed version of the edge table. + unsigned int edgeListHex[] = + {0x0001cde0, 0x98b08c9d, 0x674046ce, 0x487bc480, + 0x21301d2e, 0x139bd910, 0x26376e20, 0x3b700000}; + + unsigned int edgeValFull = edgeListHex[index/2]; + unsigned int edgeVal = (index % 2 == 1) ? (edgeValFull & 0xFFFF) : ((edgeValFull >> 16) & 0xFFFF); + int4 e0 = int4((edgeVal >> 14) & 0x3, (edgeVal >> 12) & 0x3, (edgeVal >> 10) & 0x3, (edgeVal >> 8) & 0x3); + int4 e1 = int4((edgeVal >> 6) & 0x3, (edgeVal >> 4) & 0x3, (edgeVal >> 2) & 0x3, (edgeVal >> 0) & 0x3); + + CalcIntersection(Pos[e0.x], N[e0.x], Field[e0.x], Pos[e0.y], N[e0.y], Field[e0.y]); + CalcIntersection(Pos[e0.z], N[e0.z], Field[e0.z], Pos[e0.w], N[e0.w], Field[e0.w]); + CalcIntersection(Pos[e1.x], N[e1.x], Field[e1.x], Pos[e1.y], N[e1.y], Field[e1.y]); + + // Emit additional triangle, if necessary + if (e1.z != -1) { + CalcIntersection(Pos[e1.z], N[e1.z], Field[e1.z], Pos[e1.w], N[e1.w], Field[e1.w]); + } + } +} + +// Pixel shader +float4 mainPS(float3 N : TEXCOORD0) : COLOR +{ + //Sanitize input + N = normalize(N); + float3 L = float3(0, 0, 1); + //return float4(N*0.5+0.5, 1); + float3 materials[2] = { float3(1, 1, 1), float3(0, 0, 0.5)}; + float nDotL = dot( N, L); + return float4(abs(nDotL) * materials[nDotL < 0.0], 0.1); +} diff --git a/res/dist/media/materials/programs/isosurf.hlsl b/res/dist/media/materials/programs/isosurf.hlsl new file mode 100644 index 00000000000..f43e85ceb04 --- /dev/null +++ b/res/dist/media/materials/programs/isosurf.hlsl @@ -0,0 +1,145 @@ +cbuffer cBuffer0 +{ + float4x4 WorldViewProj; + float4x4 origWorldViewIT; + float4 Metaballs[2]; + float IsoValue = 1.0; + +} + +struct SampleData +{ + float4 Pos : POSITION; + float3 N : TEXCOORD0; + float2 Field : TEXCOORD1; +}; + +struct SurfaceVertex +{ + float4 Pos : POSITION; + float3 N : TEXCOORD0; +}; + +static const int Num_Metaballs = 2; + +// Size of the sampling grid +static const int3 SizeMask = { 63, 63, 63 }; +static const int3 SizeShift = { 0, 6, 12 }; + +// Metaball function +// Returns metaball function value in .w and its gradient in .xyz + +float4 Metaball(float3 Pos, float3 Center, float RadiusSq) +{ + float epsilon = 0.001; + + float3 Dist = Pos - Center; + float InvDistSq = 1 / (dot(Dist, Dist) + epsilon); + + float4 o; + o.xyz = -2 * RadiusSq * InvDistSq * InvDistSq * Dist; + o.w = RadiusSq * InvDistSq; + return o; +} + +// Vertex shader +SampleData mainVS(float4 pos : POSITION) +{ + SampleData o; + + // Sum up contributions from all metaballs + float4 Field = 0; + for (int i = 0; i<2; i++) + { + Field += Metaball(pos.xyz, Metaballs[i].xyz, Metaballs[i].w); + } + + float3x3 WorldViewIT = { origWorldViewIT[0].xyz, origWorldViewIT[1].xyz, origWorldViewIT[2].xyz }; + + // Transform position and normals + o.Pos = mul(WorldViewProj, pos); + o.N = mul(WorldViewIT, Field.xyz); // we want normals in world space + o.Field.x = Field.w; + + // Generate in-out flags + o.Field.y = (Field.w < IsoValue) ? 1 : 0; + +// o.Color = (Field*0.5+0.5) * (Field.w / 10.0); + return o; +} + +// Estimate where isosurface intersects grid edge with endpoints v0, v1 +void CalcIntersection(float4 Pos0, + float3 N0, + float2 Field0, + float4 Pos1, + float3 N1, + float2 Field1, + inout TriangleStream OutputStream + ) +{ + SurfaceVertex outputVertex; + float t = (IsoValue - Field0.x) / (Field1.x - Field0.x); + if ((Field0.x < IsoValue) && (Field1.x > Field0.x)) + { + if (t > 0 && t < 1) + { + float4 Pos = lerp(Pos0, Pos1, t); + float3 N = lerp(N0, N1, t); + outputVertex.Pos = Pos; + outputVertex.N = N; + OutputStream.Append(outputVertex); + } + } +} + +// Geometry shader +// input: line with adjacency (tetrahedron) +// outputs: zero, one or two triangles depending if isosurface intersects tetrahedron + + +[maxvertexcount(4)] +void mainGS(lineadj SampleData input[4], inout TriangleStream OutputStream) +{ + // construct index for this tetrahedron + unsigned int index = (int(input[0].Field.y) << 3) | + (int(input[1].Field.y) << 2) | + (int(input[2].Field.y) << 1) | + int(input[3].Field.y); + + + // don't bother if all vertices out or all vertices inside isosurface + if (index > 0 && index < 15) + { + //Uber-compressed version of the edge table. + unsigned int edgeListHex[] = + {0x0001cde0, 0x98b08c9d, 0x674046ce, 0x487bc480, + 0x21301d2e, 0x139bd910, 0x26376e20, 0x3b700000}; + + unsigned int edgeValFull = edgeListHex[index/2]; + unsigned int edgeVal = (index % 2 == 1) ? (edgeValFull & 0xFFFF) : ((edgeValFull >> 16) & 0xFFFF); + int4 e0 = int4((edgeVal >> 14) & 0x3, (edgeVal >> 12) & 0x3, (edgeVal >> 10) & 0x3, (edgeVal >> 8) & 0x3); + int4 e1 = int4((edgeVal >> 6) & 0x3, (edgeVal >> 4) & 0x3, (edgeVal >> 2) & 0x3, (edgeVal >> 0) & 0x3); + + CalcIntersection(input[e0.x].Pos, input[e0.x].N, input[e0.x].Field, input[e0.y].Pos, input[e0.y].N, input[e0.y].Field, OutputStream); + CalcIntersection(input[e0.z].Pos, input[e0.z].N, input[e0.z].Field, input[e0.w].Pos, input[e0.w].N, input[e0.w].Field, OutputStream); + CalcIntersection(input[e1.x].Pos, input[e1.x].N, input[e1.x].Field, input[e1.y].Pos, input[e1.y].N, input[e1.y].Field, OutputStream); + + // Emit additional triangle, if necessary + if (e1.z != -1) { + CalcIntersection(input[e1.z].Pos, input[e1.z].N, input[e1.z].Field, input[e1.w].Pos, input[e1.w].N, input[e1.w].Field, OutputStream); + } + } +} + +// Pixel shader +float4 mainPS(SurfaceVertex surfaceVertex) : SV_TARGET +{ + //Sanitize input + float3 N = normalize(surfaceVertex.N); + float3 L = float3(0, 0, 1); + //return float4(N*0.5+0.5, 1); + float3 materials[2] = { float3(1, 1, 1), float3(0, 0, 0.5)}; + float nDotL = dot( N, L); + return float4(abs(nDotL) * materials[nDotL < 0.0], 0.1); +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/mrttestfp.hlsl b/res/dist/media/materials/programs/mrttestfp.hlsl new file mode 100644 index 00000000000..a123a3b19ae --- /dev/null +++ b/res/dist/media/materials/programs/mrttestfp.hlsl @@ -0,0 +1,48 @@ +// MRT basic test +void mainfp_scene( + float2 uv : TEXCOORD0, + uniform sampler2D tex, + + // 4 output textures + // 2 RGBA + // 2 float32_R + out float4 outcolour0 : COLOR0, + out float4 outcolour1 : COLOR1, + out float4 outcolour2 : COLOR2, + out float4 outcolour3 : COLOR3 +) +{ + float4 baseColour = tex2D(tex, uv); + + // first texture will be base + outcolour0 = baseColour; + + // extract red for the second + outcolour1 = baseColour * float4(1, 0, 0, 1); + + // greyscale positive for third + outcolour2 = (baseColour.r + baseColour.g + baseColour.b) * 0.333; + + // greyscale inverted for third + outcolour3 = 1.0 - outcolour2; +} + +void mainfp_quad( + float2 uv : TEXCOORD0, + uniform sampler2D tex0 : register(s0), + uniform sampler2D tex1 : register(s1), + uniform sampler2D tex2 : register(s2), + uniform sampler2D tex3 : register(s3), + + out float4 outcolour : COLOR0 +) +{ + //outcolour = tex2D(tex0, uv); + outcolour = tex2D(tex1, uv); + //outcolour = tex2D(tex2, uv); + //outcolour = tex2D(tex3, uv); +} + + + + diff --git a/res/dist/media/materials/programs/mrttestfp_quad.glsl b/res/dist/media/materials/programs/mrttestfp_quad.glsl new file mode 100644 index 00000000000..6490b60aa26 --- /dev/null +++ b/res/dist/media/materials/programs/mrttestfp_quad.glsl @@ -0,0 +1,17 @@ +uniform sampler2D rt0; +uniform sampler2D rt1; +uniform sampler2D rt2; +uniform sampler2D rt3; + +varying vec2 uv; + +void main(void) +{ + + //gl_FragColor = texture2D(rt0, uv); + gl_FragColor = texture2D(rt1, uv); + //gl_FragColor = texture2D(rt2, uv); + //gl_FragColor = texture2D(rt3, uv); + +} + diff --git a/res/dist/media/materials/programs/mrttestfp_quad.glsles b/res/dist/media/materials/programs/mrttestfp_quad.glsles new file mode 100644 index 00000000000..6b7a3de3160 --- /dev/null +++ b/res/dist/media/materials/programs/mrttestfp_quad.glsles @@ -0,0 +1,20 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D rt0; +uniform sampler2D rt1; +uniform sampler2D rt2; +uniform sampler2D rt3; + +varying vec2 uv; + +void main(void) +{ + + //gl_FragColor = texture2D(rt0, uv); + gl_FragColor = texture2D(rt1, uv); + //gl_FragColor = texture2D(rt2, uv); + //gl_FragColor = texture2D(rt3, uv); + +} diff --git a/res/dist/media/materials/programs/mrttestfp_scene.glsl b/res/dist/media/materials/programs/mrttestfp_scene.glsl new file mode 100644 index 00000000000..55e948317e4 --- /dev/null +++ b/res/dist/media/materials/programs/mrttestfp_scene.glsl @@ -0,0 +1,20 @@ +// Need to enable the draw buffers extension +#extension GL_ARB_draw_buffers : enable + +uniform sampler2D tex0; + +void main() +{ + vec4 baseColour = texture2D(tex0, gl_TexCoord[0].xy); + + gl_FragData[0] = baseColour; + + gl_FragData[1] = baseColour * vec4(1, 0, 0, 1); + + float abs = (baseColour.r + baseColour.g + baseColour.b) * 0.333; + gl_FragData[2] = vec4(abs, abs, abs, 1); + + float invabs = 1.0 - abs; + gl_FragData[3] = vec4(invabs, invabs, invabs, 1); +} + diff --git a/res/dist/media/materials/programs/mrttestfp_scene.glsles b/res/dist/media/materials/programs/mrttestfp_scene.glsles new file mode 100644 index 00000000000..db55ef3cc8e --- /dev/null +++ b/res/dist/media/materials/programs/mrttestfp_scene.glsles @@ -0,0 +1,21 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D tex0; +varying vec4 uv0; + +void main() +{ + vec4 baseColour = texture2D(tex0, uv0.xy); + + gl_FragData[0] = baseColour; + +// gl_FragData[1] = baseColour * vec4(1, 0, 0, 1); + +// float abs = (baseColour.r + baseColour.g + baseColour.b) * 0.333; +// gl_FragData[2] = vec4(abs, abs, abs, 1); + +// float invabs = 1.0 - abs; +// gl_FragData[3] = vec4(invabs, invabs, invabs, 1); +} diff --git a/res/dist/media/materials/programs/oceanGLSL.frag b/res/dist/media/materials/programs/oceanGLSL.frag new file mode 100644 index 00000000000..dd7374821a7 --- /dev/null +++ b/res/dist/media/materials/programs/oceanGLSL.frag @@ -0,0 +1,45 @@ +// oceanGLSL.frag +// fragment program for Ocean water simulation +// 05 Aug 2005 +// adapted for Ogre by nfz +// converted from HLSL to GLSL +// original shader source from Render Monkey 1.6 Reflections Refractions.rfx + +// 06 Aug 2005: moved uvw calculation from fragment program into vertex program + +uniform float fadeBias; +uniform float fadeExp; +uniform vec4 waterColor; +uniform sampler3D Noise; +uniform samplerCube skyBox; + +varying vec3 uvw; +varying vec3 normal; +varying vec3 vVec; + +void main(void) +{ + vec3 noisy = texture3D(Noise, uvw).xyz; + + // convert to signed noise + vec3 bump = 2.0 * noisy - 1.0; + bump.xz *= 0.15; + // Make sure the normal always points upwards + // note that Ogres y axis is vertical (RM Z axis is vertical) + bump.y = 0.8 * abs(bump.y) + 0.2; + // Offset the surface normal with the bump + bump = normalize(normal + bump); + + // Find the reflection vector + vec3 normView = normalize(vVec); + vec3 reflVec = reflect(normView, bump); + // Ogre has z flipped for cubemaps + reflVec.z = -reflVec.z; + vec4 refl = textureCube(skyBox, reflVec); + + // set up for fresnel calc + float lrp = 1.0 - dot(-normView, bump); + + // Interpolate between the water color and reflection for fresnel effect + gl_FragColor = mix(waterColor, refl, clamp(fadeBias + pow(lrp, fadeExp), 0.0, 1.0) ); +} diff --git a/res/dist/media/materials/programs/oceanGLSL.vert b/res/dist/media/materials/programs/oceanGLSL.vert new file mode 100644 index 00000000000..f0f59497b58 --- /dev/null +++ b/res/dist/media/materials/programs/oceanGLSL.vert @@ -0,0 +1,32 @@ +// oceanGLSL.vert +// vertex program for Ocean water simulation +// 05 Aug 2005 +// adapted for Ogre by nfz +// converted from HLSL to GLSL +// original shader source from Render Monkey 1.6 Reflections Refractions.rfx + +// 06 Aug 2005: moved uvw calculation from fragment program into vertex program + +uniform vec3 scale; +uniform vec3 eyePosition; +uniform vec2 waveSpeed; +uniform float noiseSpeed; +uniform float time_0_X; + +varying vec3 uvw; +varying vec3 normal; +varying vec3 vVec; + +void main(void) +{ + gl_Position = ftransform(); + + // the view vector needs to be in vertex space + vVec = gl_Vertex.xyz - eyePosition; + normal = gl_Normal; + // uvw is the calculated uvw coordinates based on vertex position + uvw = gl_Vertex.xyz * scale.xyz; + uvw.xz += waveSpeed * time_0_X; + uvw.y += uvw.z + noiseSpeed * time_0_X; + +} diff --git a/res/dist/media/materials/programs/oceanHLSL_Cg.frag b/res/dist/media/materials/programs/oceanHLSL_Cg.frag new file mode 100644 index 00000000000..6f3252496b8 --- /dev/null +++ b/res/dist/media/materials/programs/oceanHLSL_Cg.frag @@ -0,0 +1,45 @@ +// oceanHLSL_Cg.frag +// fragment program for Ocean water simulation +// 04 Aug 2005 +// adapted for Ogre by nfz +// original shader source from Render Monkey 1.6 Reflections Refractions.rfx +// can be used in both Cg and HLSL compilers + +// 06 Aug 2005: moved uvw calculation from fragment program into vertex program + +float4 main( float4 Pos: POSITION, + float3 uvw: TEXCOORD0, float3 normal: TEXCOORD1, float3 vVec: TEXCOORD2, + uniform float fadeBias, + uniform float fadeExp, + uniform float4 waterColor, + uniform sampler3D Noise, + uniform samplerCUBE skyBox + +) : COLOR +{ + + float3 noisy = tex3D(Noise, uvw).xyz; + + // convert to Signed noise + float3 bump = 2 * noisy - 1; + bump.xz *= 0.15; + // Make sure the normal always points upwards + // note that Ogres y axis is vertical (RM Z axis is vertical) + bump.y = 0.8 * abs(bump.y) + 0.2; + // Offset the surface normal with the bump + bump = normalize(normal + bump); + + // Find the reflection vector + float3 normView = normalize(vVec); + float3 reflVec = reflect(normView, bump); + // Ogre has z flipped for cubemaps + reflVec.z = -reflVec.z; + float4 refl = texCUBE(skyBox, reflVec); + + // set up for fresnel calc + float lrp = 1 - dot(-normView, bump); + + // Interpolate between the water color and reflection for fresnel effect + return lerp(waterColor, refl, saturate(fadeBias + pow(lrp, fadeExp))); + +} diff --git a/res/dist/media/materials/programs/oceanHLSL_Cg.vert b/res/dist/media/materials/programs/oceanHLSL_Cg.vert new file mode 100644 index 00000000000..a3f517ea37f --- /dev/null +++ b/res/dist/media/materials/programs/oceanHLSL_Cg.vert @@ -0,0 +1,41 @@ +// oceanHLSL_Cg.vert +// vertex program for Ocean water simulation +// 04 Aug 2005 +// adapted for Ogre by nfz +// original shader source from Render Monkey 1.6 Reflections Refractions.rfx +// can be used in both Cg and HLSL compilers + +// 06 Aug 2005: moved uvw calculation from fragment program into vertex program + +struct VS_OUTPUT { + float4 Pos: POSITION; + float3 uvw: TEXCOORD0; + float3 normal: TEXCOORD1; + float3 vVec: TEXCOORD2; +}; + +VS_OUTPUT main(float4 Pos: POSITION, float3 normal: NORMAL, + uniform float4x4 worldViewProj_matrix, + uniform float3 scale, + uniform float2 waveSpeed, + uniform float noiseSpeed, + uniform float time_0_X, + uniform float3 eyePosition + +) +{ + VS_OUTPUT Out; + + Out.Pos = mul(worldViewProj_matrix, Pos); + + // uvw is the calculated uvw coordinates based on vertex position + Out.uvw = Pos.xyz * scale; + Out.uvw.xz += waveSpeed * time_0_X; + Out.uvw.y += Out.uvw.z + noiseSpeed * time_0_X; + + // the view vector needs to be in vertex space + Out.vVec = Pos.xyz - eyePosition; + Out.normal = normal; + + return Out; +} diff --git a/res/dist/media/materials/programs/particlesgs.fx b/res/dist/media/materials/programs/particlesgs.fx new file mode 100644 index 00000000000..2b91d2c5794 --- /dev/null +++ b/res/dist/media/materials/programs/particlesgs.fx @@ -0,0 +1,367 @@ +//-------------------------------------------------------------------------------------- +// File: ParticlesGS.fx +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// this is the original shader from the dx sdk with a few minor changes so the sample will work. +//-------------------------------------------------------------------------------------- +struct VSParticleIn +{ + float3 pos : POSITION; //position of the particle + float3 vel : TEXCOORD0; //velocity of the particle + float Timer : TEXCOORD1; //timer for the particle + uint Type : TEXCOORD2; //particle type +}; + +struct VSParticleDrawOut +{ + float3 pos : POSITION; + float4 color : COLOR0; + float radius : RADIUS; +}; + +struct PSSceneIn +{ + float4 pos : SV_Position; + float2 tex : TEXTURE0; + float4 color : COLOR0; +}; + +cbuffer cb0 +{ + float4x4 worldViewProj; + float4x4 inverseView; + float globalTime; + float elapsedTime; + float4 frameGravity; + float secondsPerFirework = 1.0; + float3 g_positions[4] = + { + float3( -1, 1, 0 ), + float3( 1, 1, 0 ), + float3( -1, -1, 0 ), + float3( 1, -1, 0 ), + }; + float2 g_texcoords[4] = + { + float2(0,1), + float2(1,1), + float2(0,0), + float2(1,0), + }; +}; + +#define NUM_EMBER_1S 30 +#define NUM_EMBER_2S 15 + + +Texture2D g_txDiffuse; +SamplerState g_samLinear +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Clamp; + AddressV = Clamp; +}; + +Texture1D g_txRandom; +SamplerState g_samPoint +{ + Filter = MIN_MAG_MIP_POINT; + AddressU = Wrap; +}; + +BlendState AdditiveBlending +{ + AlphaToCoverageEnable = FALSE; + BlendEnable[0] = TRUE; + SrcBlend = SRC_ALPHA; + DestBlend = ONE; + BlendOp = ADD; + SrcBlendAlpha = ZERO; + DestBlendAlpha = ZERO; + BlendOpAlpha = ADD; + RenderTargetWriteMask[0] = 0x0F; +}; + +BlendState NoBlending +{ + AlphaToCoverageEnable = FALSE; + BlendEnable[0] = FALSE; +}; + +DepthStencilState DisableDepth +{ + DepthEnable = FALSE; + DepthWriteMask = ZERO; +}; + +// +// Explanation of different particle types +// +#define PT_LAUNCHER 0 //Firework Launcher - launches a PT_SHELL every so many seconds +#define PT_SHELL 1 //Unexploded shell - flies from the origin and explodes into many PT_EMBERXs +#define PT_EMBER1 2 //basic particle - after it's emitted from the shell, it dies +#define PT_EMBER2 3 //after it's emitted, it explodes again into many PT_EMBER1s +#define PT_EMBER3 4 //just a differently colored ember1 +#define P_SHELLLIFE 3.0 +#define P_EMBER1LIFE 2.5 +#define P_EMBER2LIFE 1.5 +#define P_EMBER3LIFE 2.0 + +// +// Vertex shader for drawing the point-sprite particles +// +VSParticleDrawOut VSScenemain(VSParticleIn input) +{ + VSParticleDrawOut output = (VSParticleDrawOut)0; + + // + // Pass the point through + // + output.pos = input.pos; + output.radius = 1.5; + + // + // calculate the color + // + if( input.Type == PT_LAUNCHER ) + { + output.color = float4(1,0.1,0.1,1); + output.radius = 1.0; + } + else if( input.Type == PT_SHELL ) + { + output.color = float4(0.1,1,1,1); + output.radius = 1.0; + } + else if( input.Type == PT_EMBER1 ) + { + output.color = float4(1,1,0.1,1); + output.color *= (input.Timer / P_EMBER1LIFE ); + } + else if( input.Type == PT_EMBER2 ) + { + output.color = float4(1,0.1,1,1); + } + else if( input.Type == PT_EMBER3 ) + { + output.color = float4(1,0.1,0.1,1); + output.color *= (input.Timer / P_EMBER3LIFE ); + } + + return output; +} + +// +// Passthrough VS for the streamout GS +// +VSParticleIn VSPassThroughmain(VSParticleIn input) +{ + return input; +} + +// +// Sample a random direction from our random texture +// +float3 RandomDir(float fOffset) +{ + float tCoord = (globalTime + fOffset) / 300.0; + return g_txRandom.SampleLevel( g_samPoint, tCoord, 0 ); +} + +// +// Generic particle motion handler +// + +void GSGenericHandler( VSParticleIn input, inout PointStream ParticleOutputStream ) +{ + input.pos += input.vel*elapsedTime; + input.vel += frameGravity; + input.Timer -= elapsedTime; + ParticleOutputStream.Append( input ); +} + +// +// Launcher type particle handler +// +void GSLauncherHandler( VSParticleIn input, inout PointStream ParticleOutputStream ) +{ + if(input.Timer <= 0) + { + float3 vRandom = normalize( RandomDir( input.Type ) ); + //time to emit a new SHELL + VSParticleIn output; + output.pos = input.pos + input.vel*elapsedTime; + output.vel = input.vel + vRandom*8.0; + output.Timer = P_SHELLLIFE + vRandom.y*0.5; + output.Type = PT_SHELL; + ParticleOutputStream.Append( output ); + + //reset our timer + input.Timer = secondsPerFirework + vRandom.x*0.4; + } + else + { + input.Timer -= elapsedTime; + } + + //emit ourselves to keep us alive + ParticleOutputStream.Append( input ); + +} + +// +// Shell type particle handler +// +void GSShellHandler( VSParticleIn input, inout PointStream ParticleOutputStream ) +{ + if(input.Timer <= 0) + { + VSParticleIn output; + float3 vRandom = float3(0,0,0); + + //time to emit a series of new Ember1s + for(int i=0; i ParticleOutputStream ) +{ + if(input.Timer > 0) + { + GSGenericHandler( input, ParticleOutputStream ); + } +} + +// +// Ember2 type particle handler +// +void GSEmber2Handler( VSParticleIn input, inout PointStream ParticleOutputStream ) +{ + if(input.Timer <= 0) + { + VSParticleIn output; + + //time to emit a series of new Ember3s + for(int i=0; i<10; i++) + { + output.pos = input.pos + input.vel*elapsedTime; + output.vel = input.vel + normalize( RandomDir( input.Type + i ) )*10.0; + output.Timer = P_EMBER3LIFE; + output.Type = PT_EMBER3; + ParticleOutputStream.Append( output ); + } + } + else + { + GSGenericHandler( input, ParticleOutputStream ); + } +} + +// +// Main particle system handler... handler particles and streams them out to a vertex buffer +// +[maxvertexcount(128)] +void GSAdvanceParticlesMain(point VSParticleIn input[1], inout PointStream ParticleOutputStream) +{ + if( input[0].Type == PT_LAUNCHER ) + GSLauncherHandler( input[0], ParticleOutputStream ); + else if ( input[0].Type == PT_SHELL ) + GSShellHandler( input[0], ParticleOutputStream ); + else if ( input[0].Type == PT_EMBER1 || + input[0].Type == PT_EMBER3 ) + GSEmber1Handler( input[0], ParticleOutputStream ); + else if( input[0].Type == PT_EMBER2 ) + GSEmber2Handler( input[0], ParticleOutputStream ); +} + +// +// GS for rendering point sprite particles. Takes a point and turns it into 2 tris. +// +[maxvertexcount(4)] +void GSScenemain(point VSParticleDrawOut input[1], inout TriangleStream SpriteStream) +{ + PSSceneIn output; + + // + // Emit two new triangles + // + for(int i=0; i<4; i++) + { + float3 position = g_positions[i]*input[0].radius; + position = mul( position, (float3x3)inverseView ) + input[0].pos; + output.pos = mul( float4(position,1.0), worldViewProj ); + + output.color = input[0].color; + output.tex = g_texcoords[i]; + SpriteStream.Append(output); + } + SpriteStream.RestartStrip(); +} + +// +// PS for particles +// +float4 PSScenemain(PSSceneIn input) : SV_Target +{ + return g_txDiffuse.Sample( g_samLinear, input.tex ) * input.color; +} + +// +// RenderParticles - renders particles on the screen +// +technique10 RenderParticles +{ + pass p0 + { + SetVertexShader( CompileShader( vs_4_0, VSScenemain() ) ); + SetGeometryShader( CompileShader( gs_4_0, GSScenemain() ) ); + SetPixelShader( CompileShader( ps_4_0, PSScenemain() ) ); + + SetBlendState( AdditiveBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + SetDepthStencilState( DisableDepth, 0 ); + } +} + +// +// AdvanceParticles - advances the particle system one time step +// + +GeometryShader gsStreamOut = ConstructGSWithSO( CompileShader( gs_4_0, GSAdvanceParticlesMain() ), "POSITION.xyz; NORMAL.xyz; TIMER.x; TYPE.x" ); +technique10 AdvanceParticles +{ + pass p0 + { + SetVertexShader( CompileShader( vs_4_0, VSPassThroughmain() ) ); + SetGeometryShader( gsStreamOut ); + SetPixelShader( NULL ); + + SetDepthStencilState( DisableDepth, 0 ); + } +} diff --git a/res/dist/media/materials/programs/pssm.cg b/res/dist/media/materials/programs/pssm.cg new file mode 100644 index 00000000000..b173304243b --- /dev/null +++ b/res/dist/media/materials/programs/pssm.cg @@ -0,0 +1,164 @@ +void shadow_caster_vs( + float4 position : POSITION, + + out float4 oPosition : POSITION, + out float2 oDepth : TEXCOORD0, + + uniform float4x4 wvpMat) +{ + // this is the view space position + oPosition = mul(wvpMat, position); + + // depth info for the fragment. + oDepth.x = oPosition.z; + oDepth.y = oPosition.w; + + // clamp z to zero. seem to do the trick. :-/ + //oPosition.z = max(oPosition.z, 0); +} + +void shadow_caster_ps( + float2 depth : TEXCOORD0, + + out float4 oColour : COLOR, + + uniform float4 pssmSplitPoints) +{ + float finalDepth = depth.x / depth.y; + oColour = float4(finalDepth, finalDepth, finalDepth, 1); +} + + + +void shadow_receiver_vs( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float3 oUv : TEXCOORD0, + out float3 oLightDir : TEXCOORD1, + out float3 oHalfAngle : TEXCOORD2, + out float4 oLightPosition0 : TEXCOORD3, + out float4 oLightPosition1 : TEXCOORD4, + out float4 oLightPosition2 : TEXCOORD5, + out float3 oNormal : TEXCOORD6, + + uniform float4 lightPosition, // object space + uniform float3 eyePosition, // object space + uniform float4x4 worldViewProjMatrix, + uniform float4x4 texWorldViewProjMatrix0, + uniform float4x4 texWorldViewProjMatrix1, + uniform float4x4 texWorldViewProjMatrix2) +{ + // calculate output position + oPosition = mul(worldViewProjMatrix, position); + + // pass the main uvs straight through unchanged + oUv.xy = uv; + oUv.z = oPosition.z; + + // calculate tangent space light vector + // Get object space light direction + oLightDir = normalize(lightPosition.xyz - (position * lightPosition.w).xyz); + + // Calculate half-angle in tangent space + float3 eyeDir = normalize(eyePosition - position.xyz); + oHalfAngle = normalize(eyeDir + oLightDir); + + // Calculate the position of vertex in light space + oLightPosition0 = mul(texWorldViewProjMatrix0, position); + oLightPosition1 = mul(texWorldViewProjMatrix1, position); + oLightPosition2 = mul(texWorldViewProjMatrix2, position); + + oNormal = normal; +} + +float shadowPCF(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 alot 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 + //float c = (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy - o.xyyy).r) ? 1 : 0; // top left + //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy + o.xyyy).r) ? 1 : 0; // bottom right + //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy + o.zyyy).r) ? 1 : 0; // bottom left + //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy - o.zyyy).r) ? 1 : 0; // top right + return c / 4; +} + +// to put it simply, this does 100% per pixel diffuse lighting +void shadow_receiver_ps( + float3 uv : TEXCOORD0, + float3 OSlightDir : TEXCOORD1, + float3 OShalfAngle : TEXCOORD2, + float4 LightPosition0 : TEXCOORD3, + float4 LightPosition1 : TEXCOORD4, + float4 LightPosition2 : TEXCOORD5, + float3 normal : TEXCOORD6, + + out float4 oColour : COLOR, + + uniform float4 invShadowMapSize0, + uniform float4 invShadowMapSize1, + uniform float4 invShadowMapSize2, + uniform float4 pssmSplitPoints, + uniform sampler2D diffuse, + uniform sampler2D specular, + uniform sampler2D normalMap, + uniform sampler2D shadowMap0, + uniform sampler2D shadowMap1, + uniform sampler2D shadowMap2, + uniform float4 lightDiffuse, + uniform float4 lightSpecular, + uniform float4 ambient + ) +{ + // calculate shadow + float shadowing = 1.0f; + float4 splitColour; + if (uv.z <= pssmSplitPoints.y) + { + splitColour = float4(0.1, 0, 0, 1); + shadowing = shadowPCF(shadowMap0, LightPosition0, invShadowMapSize0.xy); + } + else if (uv.z <= pssmSplitPoints.z) + { + splitColour = float4(0, 0.1, 0, 1); + shadowing = shadowPCF(shadowMap1, LightPosition1, invShadowMapSize1.xy); + } + else + { + splitColour = float4(0.1, 0.1, 0, 1); + shadowing = shadowPCF(shadowMap2, LightPosition2, invShadowMapSize2.xy); + } + + // retrieve normalised light vector, expand from range-compressed + float3 lightVec = normalize(OSlightDir); + + // retrieve half angle and normalise through cube map + float3 halfAngle = normalize(OShalfAngle); + + // get diffuse colour + float4 diffuseColour = tex2D(diffuse, uv.xy); + + // specular + float4 specularColour = tex2D(specular, uv.xy); + float shininess = specularColour.w; + specularColour.w = 1; + + // calculate lit value. + float4 lighting = lit(dot(normal, lightVec), dot(normal, halfAngle), shininess * 128) * shadowing; + + // final lighting with diffuse and spec + oColour = (diffuseColour * clamp(ambient + lightDiffuse * lighting.y, 0, 1)) + (lightSpecular * specularColour * lighting.z); + oColour.w = diffuseColour.w; + + //oColour += splitColour; +} + diff --git a/res/dist/media/materials/programs/pssm.hlsl b/res/dist/media/materials/programs/pssm.hlsl new file mode 100644 index 00000000000..f23172f18bc --- /dev/null +++ b/res/dist/media/materials/programs/pssm.hlsl @@ -0,0 +1,167 @@ +void shadow_caster_vs( + float4 position : POSITION, + + out float4 oPosition : SV_POSITION, + out float2 oDepth : TEXCOORD0, + + uniform float4x4 wvpMat) +{ + // this is the view space position + oPosition = mul(wvpMat, position); + + // depth info for the fragment. + oDepth.x = oPosition.z; + oDepth.y = oPosition.w; + + // clamp z to zero. seem to do the trick. :-/ + //oPosition.z = max(oPosition.z, 0); +} + +void shadow_caster_ps( + float4 Position : SV_POSITION, + float2 depth : TEXCOORD0, + + out float4 oColour : COLOR, + + uniform float4 pssmSplitPoints) +{ + float finalDepth = depth.x / depth.y; +// oColour = float4(finalDepth, finalDepth, finalDepth, 1); + oColour = float4(0, 0, 0, 1); +} + + + +void shadow_receiver_vs( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + + out float4 oPosition : SV_POSITION, + out float3 oUv : TEXCOORD0, + out float3 oLightDir : TEXCOORD1, + out float3 oHalfAngle : TEXCOORD2, + out float4 oLightPosition0 : TEXCOORD3, + out float4 oLightPosition1 : TEXCOORD4, + out float4 oLightPosition2 : TEXCOORD5, + out float3 oNormal : TEXCOORD6, + + uniform float4 lightPosition, // object space + uniform float3 eyePosition, // object space + uniform float4x4 worldViewProjMatrix, + uniform float4x4 texWorldViewProjMatrix0, + uniform float4x4 texWorldViewProjMatrix1, + uniform float4x4 texWorldViewProjMatrix2) +{ + // calculate output position + oPosition = mul(worldViewProjMatrix, position); + + // pass the main uvs straight through unchanged + oUv.xy = uv; + oUv.z = oPosition.z; + + // calculate tangent space light vector + // Get object space light direction + oLightDir = normalize(lightPosition.xyz - (position * lightPosition.w).xyz); + + // Calculate half-angle in tangent space + float3 eyeDir = normalize(eyePosition - position.xyz); + oHalfAngle = normalize(eyeDir + oLightDir); + + // Calculate the position of vertex in light space + oLightPosition0 = mul(texWorldViewProjMatrix0, position); + oLightPosition1 = mul(texWorldViewProjMatrix1, position); + oLightPosition2 = mul(texWorldViewProjMatrix2, position); + + oNormal = normal; +} + +float shadowPCF(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 alot faster. + float c = (shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.xy).r)>0 ? 1 : 0; // top left + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.xy).r)>0 ? 1 : 0; // bottom right + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.zy).r)>0 ? 1 : 0; // bottom left + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.zy).r)>0 ? 1 : 0; // top right + //float c = (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy - o.xyyy).r) ? 1 : 0; // top left + //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy + o.xyyy).r) ? 1 : 0; // bottom right + //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy + o.zyyy).r) ? 1 : 0; // bottom left + //c += (shadowMapPos.z <= tex2Dlod(shadowMap, uv.xyyy - o.zyyy).r) ? 1 : 0; // top right + return c / 4; +} + +// to put it simply, this does 100% per pixel diffuse lighting +void shadow_receiver_ps( + float4 oPosition : SV_POSITION, + float3 uv : TEXCOORD0, + float3 OSlightDir : TEXCOORD1, + float3 OShalfAngle : TEXCOORD2, + float4 LightPosition0 : TEXCOORD3, + float4 LightPosition1 : TEXCOORD4, + float4 LightPosition2 : TEXCOORD5, + float3 normal : TEXCOORD6, + + out float4 oColour : COLOR, + + uniform float4 invShadowMapSize0, + uniform float4 invShadowMapSize1, + uniform float4 invShadowMapSize2, + uniform float4 pssmSplitPoints, + uniform sampler2D diffuse:register(s3), + uniform sampler2D specular:register(s4), + uniform sampler2D normalMap:register(s5), + uniform sampler2D shadowMap0:register(s0), + uniform sampler2D shadowMap1:register(s1), + uniform sampler2D shadowMap2:register(s2), + uniform float4 lightDiffuse, + uniform float4 lightSpecular, + uniform float4 ambient + ) +{ + // calculate shadow + float shadowing = 1.0f; + float4 splitColour; + if (uv.z <= pssmSplitPoints.y) + { + splitColour = float4(0.1, 0, 0, 1); + shadowing = shadowPCF(shadowMap0, LightPosition0, invShadowMapSize0.xy); + } + else if (uv.z <= pssmSplitPoints.z) + { + splitColour = float4(0, 0.1, 0, 1); + shadowing = shadowPCF(shadowMap1, LightPosition1, invShadowMapSize1.xy); + } + else + { + splitColour = float4(0.1, 0.1, 0, 1); + shadowing = shadowPCF(shadowMap2, LightPosition2, invShadowMapSize2.xy); + } + + // retrieve normalised light vector, expand from range-compressed + float3 lightVec = normalize(OSlightDir); + + // retrieve half angle and normalise through cube map + float3 halfAngle = normalize(OShalfAngle); + + // get diffuse colour + float4 diffuseColour = tex2D(diffuse, uv.xy); + + // specular + float4 specularColour = tex2D(specular, uv.xy); + float shininess = specularColour.w; + specularColour.w = 1; + + // calculate lit value. + float4 lighting = lit(dot(normal, lightVec), dot(normal, halfAngle), shininess * 128) * shadowing; + + // final lighting with diffuse and spec + oColour = (diffuseColour * clamp(ambient + lightDiffuse * lighting.y, 0, 1)) + (lightSpecular * specularColour * lighting.z); + oColour.w = diffuseColour.w; + + //oColour += splitColour; +} + diff --git a/res/dist/media/materials/programs/pssmCasterFp.glsles b/res/dist/media/materials/programs/pssmCasterFp.glsles new file mode 100644 index 00000000000..95b2a386e28 --- /dev/null +++ b/res/dist/media/materials/programs/pssmCasterFp.glsles @@ -0,0 +1,13 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec2 oDepth; +uniform vec4 pssmSplitPoints; + +void main() +{ + float finalDepth = oDepth.x / oDepth.y; + gl_FragColor = vec4(finalDepth, finalDepth, finalDepth, 1.0); +} diff --git a/res/dist/media/materials/programs/pssmCasterVp.glsles b/res/dist/media/materials/programs/pssmCasterVp.glsles new file mode 100644 index 00000000000..72290b6b72d --- /dev/null +++ b/res/dist/media/materials/programs/pssmCasterVp.glsles @@ -0,0 +1,21 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec2 oDepth; +uniform mat4 worldViewProjMatrix; +attribute vec4 vertex; + +void main() +{ + // This is the view space position + gl_Position = worldViewProjMatrix * vertex; + + // Depth info for the fragment. + oDepth.x = gl_Position.z; + oDepth.y = gl_Position.w; + + // Clamp z to zero. seem to do the trick. :-/ + //oPosition.z = max(oPosition.z, 0); +} diff --git a/res/dist/media/materials/programs/pssmFp.glsles b/res/dist/media/materials/programs/pssmFp.glsles new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/dist/media/materials/programs/pssmReceiverFp.glsles b/res/dist/media/materials/programs/pssmReceiverFp.glsles new file mode 100644 index 00000000000..1ddf90d87b6 --- /dev/null +++ b/res/dist/media/materials/programs/pssmReceiverFp.glsles @@ -0,0 +1,92 @@ +#version 100 + +precision mediump int; +precision mediump float; + +float shadowPCF(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; +} + +uniform vec4 invShadowMapSize0; +uniform vec4 invShadowMapSize1; +uniform vec4 invShadowMapSize2; +uniform vec4 pssmSplitPoints; +uniform sampler2D diffuse; +uniform sampler2D specular; +uniform sampler2D normalMap; +uniform sampler2D shadowMap0; +uniform sampler2D shadowMap1; +uniform sampler2D shadowMap2; +uniform vec4 lightDiffuse; +uniform vec4 lightSpecular; +uniform vec4 ambient; + +varying vec4 oUv0; +varying vec3 oLightDir; +varying vec3 oHalfAngle; +varying vec4 oLightPosition0; +varying vec4 oLightPosition1; +varying vec4 oLightPosition2; +varying vec3 oNormal; + +// to put it simply, this does 100% per pixel diffuse lighting +void main() +{ + // calculate shadow + float shadowing = 1.0; + vec4 splitColour; + if (oUv0.z <= pssmSplitPoints.y) + { + splitColour = vec4(0.1, 0.0, 0.0, 1.0); + shadowing = shadowPCF(shadowMap0, oLightPosition0, invShadowMapSize0.xy); + } + else if (oUv0.z <= pssmSplitPoints.z) + { + splitColour = vec4(0.0, 0.1, 0.0, 1.0); + shadowing = shadowPCF(shadowMap1, oLightPosition1, invShadowMapSize1.xy); + } + else + { + splitColour = vec4(0.1, 0.1, 0.0, 1.0); + shadowing = shadowPCF(shadowMap2, oLightPosition2, invShadowMapSize2.xy); + } + + // retrieve normalised light vector, expand from range-compressed + vec3 lightVec = normalize(oLightDir); + + // retrieve half angle and normalise through cube map + vec3 halfAngle = normalize(oHalfAngle); + + // get diffuse colour + vec4 diffuseColour = texture2D(diffuse, oUv0.xy); + + // specular + vec4 specularColour = texture2D(specular, oUv0.xy); + float shininess = specularColour.w; + specularColour.w = 1.0; + + // calculate lit value. + float diffuseCoeff = max(dot(oNormal, lightVec), 0.0); + float specularCoeff = step(0.0, dot(oNormal, lightVec)) * max(dot(oNormal, halfAngle) * (shininess * 128.0), 0.0); + vec4 lighting; + lighting.y = diffuseCoeff * shadowing; + lighting.z = specularCoeff * shadowing; +// vec4 lighting = lit(dot(oNormal, lightVec), dot(oNormal, halfAngle), shininess * 128.0) * shadowing; + + // final lighting with diffuse and spec + gl_FragColor = (diffuseColour * clamp(ambient + lightDiffuse * lighting.y, 0.0, 1.0)) + (lightSpecular * specularColour * lighting.z); + gl_FragColor.w = diffuseColour.w; + + //oColour += splitColour; +} diff --git a/res/dist/media/materials/programs/pssmReceiverVp.glsles b/res/dist/media/materials/programs/pssmReceiverVp.glsles new file mode 100644 index 00000000000..dfb8135627f --- /dev/null +++ b/res/dist/media/materials/programs/pssmReceiverVp.glsles @@ -0,0 +1,63 @@ +#version 100 + +precision mediump int; +precision mediump float; + +float shadowPCF(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; +} + +uniform vec4 lightPosition; // object space +uniform vec3 eyePosition; // object space +uniform mat4 worldViewProjMatrix; +uniform mat4 texWorldViewProjMatrix0; +uniform mat4 texWorldViewProjMatrix1; +uniform mat4 texWorldViewProjMatrix2; + +varying vec4 oUv0; +varying vec3 oLightDir; +varying vec3 oHalfAngle; +varying vec4 oLightPosition0; +varying vec4 oLightPosition1; +varying vec4 oLightPosition2; +varying vec3 oNormal; + +attribute vec4 position; +attribute vec3 normal; +attribute vec4 uv0; + +void main() +{ + // Calculate output position + gl_Position = worldViewProjMatrix * position; + + // Pass the main uvs straight through unchanged + oUv0.xy = uv0.xy; + oUv0.z = gl_Position.z; + + // Calculate tangent space light vector + // Get object space light direction + oLightDir = normalize(lightPosition.xyz - (position * lightPosition.w).xyz); + + // Calculate half-angle in tangent space + vec3 eyeDir = normalize(eyePosition - position.xyz); + oHalfAngle = normalize(eyeDir + oLightDir); + + // Calculate the position of vertex in light space + oLightPosition0 = texWorldViewProjMatrix0 * position; + oLightPosition1 = texWorldViewProjMatrix1 * position; + oLightPosition2 = texWorldViewProjMatrix2 * position; + + oNormal = normal; +} diff --git a/res/dist/media/materials/programs/pssmVp.glsles b/res/dist/media/materials/programs/pssmVp.glsles new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/dist/media/materials/programs/shadows.cg b/res/dist/media/materials/programs/shadows.cg new file mode 100644 index 00000000000..cbd5676f10e --- /dev/null +++ b/res/dist/media/materials/programs/shadows.cg @@ -0,0 +1,144 @@ +/* Copyright Torus Knot Software Ltd 2000-2012 + +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 PCF +// Number of samples in one dimension (square for total samples) +#define NUM_SHADOW_SAMPLES_1D 2.0 +#define SHADOW_FILTER_SCALE 1 + +#define SHADOW_SAMPLES NUM_SHADOW_SAMPLES_1D*NUM_SHADOW_SAMPLES_1D + +float4 offsetSample(float4 uv, float2 offset, float invMapSize) +{ + return float4(uv.xy + offset * invMapSize * uv.w, uv.z, uv.w); +} + +float calcDepthShadow(sampler2D shadowMap, float4 uv, float invShadowMapSize) +{ + // 4-sample PCF + + float shadow = 0.0; + float offset = (NUM_SHADOW_SAMPLES_1D/2 - 0.5) * SHADOW_FILTER_SCALE; + for (float y = -offset; y <= offset; y += SHADOW_FILTER_SCALE) + for (float x = -offset; x <= offset; x += SHADOW_FILTER_SCALE) + { + float depth = tex2Dproj(shadowMap, offsetSample(uv, float2(x, y), invShadowMapSize)).x; + if (depth >= 1 || depth >= uv.z) + shadow += 1.0; + } + + shadow /= SHADOW_SAMPLES; + + return shadow; +} + + +float calcSimpleShadow(sampler2D shadowMap, float4 shadowMapPos) +{ + return tex2Dproj(shadowMap, shadowMapPos).x; +} + +float calcPSSMDepthShadow(sampler2D shadowMap0, sampler2D shadowMap1, sampler2D shadowMap2, + float4 lsPos0, float4 lsPos1, float4 lsPos2, + float invShadowmapSize0, float invShadowmapSize1, float invShadowmapSize2, + float4 pssmSplitPoints, float camDepth) +{ + + float shadow; + float4 splitColour; + // calculate shadow + if (camDepth <= pssmSplitPoints.y) + { + splitColour = float4(0.3, 0.0, 0, 0); + shadow = calcDepthShadow(shadowMap0, lsPos0, invShadowmapSize0); + } + else if (camDepth <= pssmSplitPoints.z) + { + splitColour = float4(0, 0.3, 0, 0); + shadow = calcDepthShadow(shadowMap1, lsPos1, invShadowmapSize1); + } + else + { + splitColour = float4(0.0, 0.0, 0.3, 0); + shadow = calcDepthShadow(shadowMap2, lsPos2, invShadowmapSize2); + } + + return shadow; +} + +float calcPSSMSimpleShadow(sampler2D shadowMap0, sampler2D shadowMap1, sampler2D shadowMap2, + float4 lsPos0, float4 lsPos1, float4 lsPos2, + float4 pssmSplitPoints, float camDepth) +{ + + float shadow; + float4 splitColour; + // calculate shadow + if (camDepth <= pssmSplitPoints.y) + { + splitColour = float4(0.3, 0.0, 0, 0); + shadow = calcSimpleShadow(shadowMap0, lsPos0); + } + else if (camDepth <= pssmSplitPoints.z) + { + splitColour = float4(0, 0.3, 0, 0); + shadow = calcSimpleShadow(shadowMap1, lsPos1); + } + else + { + splitColour = float4(0.0, 0.0, 0.3, 0); + shadow = calcSimpleShadow(shadowMap2, lsPos2); + } + + return shadow; +} + + + +float3 calcPSSMDebugShadow(sampler2D shadowMap0, sampler2D shadowMap1, sampler2D shadowMap2, + float4 lsPos0, float4 lsPos1, float4 lsPos2, + float invShadowmapSize0, float invShadowmapSize1, float invShadowmapSize2, + float4 pssmSplitPoints, float camDepth) +{ + + float4 splitColour; + // calculate shadow + if (camDepth <= pssmSplitPoints.y) + { + //splitColour = float4(0.3, 0.0, 0, 0); + //splitColour = lsPos0 / lsPos0.w; + splitColour.rgb = tex2Dproj(shadowMap0, lsPos0).x; + } + else if (camDepth <= pssmSplitPoints.z) + { + //splitColour = float4(0, 0.3, 0, 0); + //splitColour = lsPos1 / lsPos1.w; + splitColour.rgb = tex2Dproj(shadowMap1, lsPos1).x; + } + else + { + //splitColour = float4(0.0, 0.0, 0.3, 0); + //splitColour = lsPos2 / lsPos2.w; + splitColour.rgb = tex2Dproj(shadowMap2, lsPos2).x; + } + + return splitColour.rgb; +} diff --git a/res/dist/media/materials/programs/shadows.glsl b/res/dist/media/materials/programs/shadows.glsl new file mode 100644 index 00000000000..60b02d5f30f --- /dev/null +++ b/res/dist/media/materials/programs/shadows.glsl @@ -0,0 +1,146 @@ +/* Copyright Torus Knot Software Ltd 2012 + +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. + +Adapted by Matias N. Goldberg (Dark Sylinc) to GLSL based on the Cg file shadows.cg +*/ + +// Simple PCF +// Number of samples in one dimension (square for total samples) +#define NUM_SHADOW_SAMPLES_1D 2.0 +#define SHADOW_FILTER_SCALE 1.0 + +#define SHADOW_SAMPLES NUM_SHADOW_SAMPLES_1D*NUM_SHADOW_SAMPLES_1D + +vec4 offsetSample(vec4 uv, vec2 offset, float invMapSize) +{ + return vec4(uv.xy + offset * invMapSize * uv.w, uv.z, uv.w); +} + +float calcDepthShadow(sampler2DShadow shadowMap, vec4 uv, float invShadowMapSize) +{ + // 4-sample PCF + + float shadow = 0.0; + float offset = (NUM_SHADOW_SAMPLES_1D/2.0 - 0.5) * SHADOW_FILTER_SCALE; + for (float y = -offset; y <= offset; y += SHADOW_FILTER_SCALE) + for (float x = -offset; x <= offset; x += SHADOW_FILTER_SCALE) + { + float depth = shadow2DProj(shadowMap, offsetSample(uv, vec2(x, y), invShadowMapSize)).x; + if (depth >= 1.0 || depth >= uv.z) + shadow += 1.0; + } + + shadow /= SHADOW_SAMPLES; + + return shadow; +} + + +float calcSimpleShadow(sampler2DShadow shadowMap, vec4 shadowMapPos) +{ + return shadow2DProj(shadowMap, shadowMapPos).x; +} + +float calcPSSMDepthShadow(sampler2DShadow shadowMap0, sampler2DShadow shadowMap1, sampler2DShadow shadowMap2, + vec4 lsPos0, vec4 lsPos1, vec4 lsPos2, + float invShadowmapSize0, float invShadowmapSize1, float invShadowmapSize2, + vec4 pssmSplitPoints, float camDepth) +{ + + float shadow; + vec4 splitColour; + // calculate shadow + if (camDepth <= pssmSplitPoints.y) + { + splitColour = vec4(0.3, 0.0, 0, 0); + shadow = calcDepthShadow(shadowMap0, lsPos0, invShadowmapSize0); + } + else if (camDepth <= pssmSplitPoints.z) + { + splitColour = vec4(0, 0.3, 0, 0); + shadow = calcDepthShadow(shadowMap1, lsPos1, invShadowmapSize1); + } + else + { + splitColour = vec4(0.0, 0.0, 0.3, 0); + shadow = calcDepthShadow(shadowMap2, lsPos2, invShadowmapSize2); + } + + return shadow; +} + +float calcPSSMSimpleShadow(sampler2DShadow shadowMap0, sampler2DShadow shadowMap1, sampler2DShadow shadowMap2, + vec4 lsPos0, vec4 lsPos1, vec4 lsPos2, + vec4 pssmSplitPoints, float camDepth) +{ + + float shadow; + vec4 splitColour; + // calculate shadow + if (camDepth <= pssmSplitPoints.y) + { + splitColour = vec4(0.3, 0.0, 0, 0); + shadow = calcSimpleShadow(shadowMap0, lsPos0); + } + else if (camDepth <= pssmSplitPoints.z) + { + splitColour = vec4(0, 0.3, 0, 0); + shadow = calcSimpleShadow(shadowMap1, lsPos1); + } + else + { + splitColour = vec4(0.0, 0.0, 0.3, 0); + shadow = calcSimpleShadow(shadowMap2, lsPos2); + } + + return shadow; +} + + + +vec3 calcPSSMDebugShadow(sampler2DShadow shadowMap0, sampler2DShadow shadowMap1, sampler2DShadow shadowMap2, + vec4 lsPos0, vec4 lsPos1, vec4 lsPos2, + float invShadowmapSize0, float invShadowmapSize1, float invShadowmapSize2, + vec4 pssmSplitPoints, float camDepth) +{ + + vec4 splitColour; + // calculate shadow + if (camDepth <= pssmSplitPoints.y) + { + //splitColour = vec4(0.3, 0.0, 0, 0); + //splitColour = lsPos0 / lsPos0.w; + splitColour.rgb = shadow2DProj(shadowMap0, lsPos0).xxx; + } + else if (camDepth <= pssmSplitPoints.z) + { + //splitColour = vec4(0, 0.3, 0, 0); + //splitColour = lsPos1 / lsPos1.w; + splitColour.rgb = shadow2DProj(shadowMap1, lsPos1).xxx; + } + else + { + //splitColour = vec4(0.0, 0.0, 0.3, 0); + //splitColour = lsPos2 / lsPos2.w; + splitColour.rgb = shadow2DProj(shadowMap2, lsPos2).xxx; + } + + return splitColour.rgb; +} diff --git a/res/dist/media/materials/programs/skinningTwoWeightsShadowCasterVp.glsl b/res/dist/media/materials/programs/skinningTwoWeightsShadowCasterVp.glsl new file mode 100644 index 00000000000..e390dd4c023 --- /dev/null +++ b/res/dist/media/materials/programs/skinningTwoWeightsShadowCasterVp.glsl @@ -0,0 +1,42 @@ +// Example GLSL program for skinning with two bone weights per vertex + +attribute vec4 vertex; +attribute vec4 uv0; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +// 3x4 matrix, passed as vec4's for compatibility with GL 2.0 +// GL 2.0 supports 3x4 matrices +// Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing +uniform vec4 worldMatrix3x4Array[72]; +uniform mat4 viewProjectionMatrix; +uniform vec4 ambient; + +void main() +{ + vec3 blendPos = vec3(0,0,0); + + for (int bone = 0; bone < 2; ++bone) + { + // perform matrix multiplication manually since no 3x4 matrices + // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first + int idx = int(blendIndices[bone]) * 3; + // ATI GLSL compiler can't handle unrolling the loop so do it manually + // ATI GLSL has better performance when mat4 is used rather than using individual dot product + // There is a bug in ATI mat4 constructor (Cat 7.2) when indexed uniform array elements are used as vec4 parameter so manually assign + mat4 worldMatrix; + worldMatrix[0] = worldMatrix3x4Array[idx]; + worldMatrix[1] = worldMatrix3x4Array[idx + 1]; + worldMatrix[2] = worldMatrix3x4Array[idx + 2]; + worldMatrix[3] = vec4(0); + // now weight this into final + blendPos += (vertex * worldMatrix).xyz * blendWeights[bone]; + } + + // apply view / projection to position + gl_Position = viewProjectionMatrix * vec4(blendPos, 1); + + gl_FrontSecondaryColor = vec4(0,0,0,0); + gl_FrontColor = ambient; + gl_TexCoord[0] = uv0; +} diff --git a/res/dist/media/materials/programs/skinningTwoWeightsShadowCasterVp.glsles b/res/dist/media/materials/programs/skinningTwoWeightsShadowCasterVp.glsles new file mode 100644 index 00000000000..cb78fbc2385 --- /dev/null +++ b/res/dist/media/materials/programs/skinningTwoWeightsShadowCasterVp.glsles @@ -0,0 +1,46 @@ +#version 100 + +precision highp int; +precision highp float; + +/* + Two-weight-per-vertex hardware skinning, shadow caster pass +*/ + +attribute vec4 vertex; +attribute vec4 uv0; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +// 3x4 matrix, passed as vec4's for compatibility with GL ES 2.0 +// Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing +uniform vec4 worldMatrix3x4Array[72]; +uniform mat4 viewProjectionMatrix; +uniform vec4 ambient; + +varying vec4 colour; + +void main() +{ + vec3 blendPos = vec3(0.0); + + for (int bone = 0; bone < 2; ++bone) + { + // Perform matrix multiplication manually since no 3x4 matrices + int idx = int(blendIndices[bone]) * 3; + + // Unroll the loop manually + mat4 worldMatrix; + worldMatrix[0] = worldMatrix3x4Array[idx]; + worldMatrix[1] = worldMatrix3x4Array[idx + 1]; + worldMatrix[2] = worldMatrix3x4Array[idx + 2]; + worldMatrix[3] = vec4(0.0); + // Now weight this into final + blendPos += (vertex * worldMatrix).xyz * blendWeights[bone]; + } + + // Apply view / projection to position + gl_Position = viewProjectionMatrix * vec4(blendPos, 1.0); + + colour = ambient; +} diff --git a/res/dist/media/materials/programs/skinningTwoWeightsVp.glsl b/res/dist/media/materials/programs/skinningTwoWeightsVp.glsl new file mode 100644 index 00000000000..5e23b06eead --- /dev/null +++ b/res/dist/media/materials/programs/skinningTwoWeightsVp.glsl @@ -0,0 +1,61 @@ +// Example GLSL program for skinning with two bone weights per vertex + +attribute vec4 vertex; +attribute vec3 normal; +attribute vec4 uv0; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +// 3x4 matrix, passed as vec4's for compatibility with GL 2.0 +// GL 2.0 supports 3x4 matrices +// Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing +uniform vec4 worldMatrix3x4Array[72]; +uniform mat4 viewProjectionMatrix; +uniform vec4 lightPos[2]; +uniform vec4 lightDiffuseColour[2]; +uniform vec4 ambient; +uniform vec4 diffuse; + +void main() +{ + vec3 blendPos = vec3(0.0, 0.0, 0.0); + vec3 blendNorm = vec3(0.0, 0.0, 0.0); + + for (int bone = 0; bone < 2; ++bone) + { + // perform matrix multiplication manually since no 3x4 matrices + // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first + int idx = int(blendIndices[bone]) * 3; + // ATI GLSL compiler can't handle unrolling the loop so do it manually + // ATI GLSL has better performance when mat4 is used rather than using individual dot product + // There is a bug in ATI mat4 constructor (Cat 7.2) when indexed uniform array elements are used as vec4 parameter so manually assign + mat4 worldMatrix; + worldMatrix[0] = worldMatrix3x4Array[idx]; + worldMatrix[1] = worldMatrix3x4Array[idx + 1]; + worldMatrix[2] = worldMatrix3x4Array[idx + 2]; + worldMatrix[3] = vec4(0); + // now weight this into final + float weight = blendWeights[bone]; + blendPos += (vertex * worldMatrix).xyz * weight; + + mat3 worldRotMatrix = mat3(worldMatrix[0].xyz, worldMatrix[1].xyz, worldMatrix[2].xyz); + blendNorm += (normal * worldRotMatrix) * weight; + } + + blendNorm = normalize(blendNorm); + + // apply view / projection to position + gl_Position = viewProjectionMatrix * vec4(blendPos, 1.0); + + // simple vertex lighting model + vec3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos * lightPos[0].w)); + vec3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos * lightPos[1].w)); + + gl_FrontColor = diffuse * (ambient + (clamp(dot(lightDir0, blendNorm), 0.0, 1.0) * lightDiffuseColour[0]) + + (clamp(dot(lightDir1, blendNorm), 0.0, 1.0) * lightDiffuseColour[1])); + + gl_TexCoord[0] = uv0; + +} diff --git a/res/dist/media/materials/programs/skinningTwoWeightsVp.glsles b/res/dist/media/materials/programs/skinningTwoWeightsVp.glsles new file mode 100644 index 00000000000..e5419ef319d --- /dev/null +++ b/res/dist/media/materials/programs/skinningTwoWeightsVp.glsles @@ -0,0 +1,63 @@ +#version 100 + +precision highp int; +precision highp float; + +// Example GLSL ES program for skinning with two bone weights per vertex + +attribute vec4 vertex; +attribute vec4 uv0; +attribute vec3 normal; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +varying vec4 colour; +varying vec4 uv; + +// 3x4 matrix, passed as vec4's for compatibility with GL ES 2.0 +// Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing +uniform vec4 worldMatrix3x4Array[72]; +uniform mat4 viewProjectionMatrix; +uniform vec4 lightPos[2]; +uniform vec4 lightDiffuseColour[2]; +uniform vec4 ambient; +uniform vec4 diffuse; + +void main() +{ + vec3 blendPos = vec3(0.0); + vec3 blendNorm = vec3(0.0); + + for (int bone = 0; bone < 2; ++bone) + { + // perform matrix multiplication manually since no 3x4 matrices + int idx = int(blendIndices[bone]) * 3; + + mat4 worldMatrix; + worldMatrix[0] = worldMatrix3x4Array[idx]; + worldMatrix[1] = worldMatrix3x4Array[idx + 1]; + worldMatrix[2] = worldMatrix3x4Array[idx + 2]; + worldMatrix[3] = vec4(0.0); + // now weight this into final + float weight = blendWeights[bone]; + blendPos += (vertex * worldMatrix).xyz * weight; + + mat3 worldRotMatrix = mat3(worldMatrix[0].xyz, worldMatrix[1].xyz, worldMatrix[2].xyz); + blendNorm += (normal * worldRotMatrix) * weight; + } + + // apply view / projection to position + gl_Position = viewProjectionMatrix * vec4(blendPos, 1.0); + + // simple vertex lighting model + vec3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + vec3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + colour = diffuse * (ambient + + clamp(dot(lightDir0, blendNorm), 0.0, 1.0) * lightDiffuseColour[0] + + clamp(dot(lightDir1, blendNorm), 0.0, 1.0) * lightDiffuseColour[1]); + uv = uv0; +} diff --git a/res/dist/media/materials/programs/varianceshadowcasterfp.cg b/res/dist/media/materials/programs/varianceshadowcasterfp.cg new file mode 100644 index 00000000000..f39e8a054b2 --- /dev/null +++ b/res/dist/media/materials/programs/varianceshadowcasterfp.cg @@ -0,0 +1,65 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// shadowcasterfp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example fragment shader for shadow caster objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +// Define outputs from vertex shader. +struct VertexOut +{ + float4 position : POSITION; // can't rely on access to this + float4 pos : TEXCOORD0; // position of fragment (in homogeneous coordinates) + float4 normal : TEXCOORD1; // un-normalized normal in object space + float4 modelPos : TEXCOORD2; // coordinates of model in object space at this point +}; + +struct FragmentOut +{ + float4 color : COLOR0; +}; + +FragmentOut main( VertexOut In, // fragment to process + uniform float uDepthOffset, // offset amount (constant in eye space) + uniform float4x4 uProjection // projection matrix + ) +{ + FragmentOut Out; + + // compute the "normalized device coordinates" (no viewport applied yet) + float4 postproj = In.pos / In.pos.w; + + // get the normalized normal of the geometry seen at this point + float4 normal = normalize(In.normal); + + + // -- Computing Depth Bias Quantities ----------------------------- + + // We now compute the change in z that would signify a push in the z direction + // by 1 unit in eye space. Note that eye space z is related in a nonlinear way to + // screen space z, so this is not just a constant. + // ddepth below is how much screen space z at this point would change for that push. + // NOTE: computation of ddepth likely differs from OpenGL's glPolygonOffset "unit" + // computation, which is allowed to be vendor specific. + float4 dpwdz = mul(uProjection, float4(0.0, 0.0, 1.0, 0.0)); + float4 dpdz = (dpwdz - (postproj * dpwdz.w)) / In.pos.w; + float ddepth = abs(dpdz.z); + + // -- End depth bias helper section -------------------------------- + + // We now compute the depth of the fragment. This is the actual depth value plus + // our depth bias. The depth bias depends on how uncertain we are about the z value + // plus some constant push in the z direction. The exact coefficients to use are + // up to you, but at least it should be somewhat intuitive now what the tradeoffs are. + float depthval = postproj.z /* + (0.5 * dzlen)*/ + (uDepthOffset * ddepth); + depthval = (0.5 * depthval) + 0.5; // put into [0,1] range instead of [-1,1] + + + Out.color = float4(depthval, depthval * depthval, depthval, 0.0); + return Out; +} diff --git a/res/dist/media/materials/programs/varianceshadowcasterfp.glsles b/res/dist/media/materials/programs/varianceshadowcasterfp.glsles new file mode 100644 index 00000000000..028fd039230 --- /dev/null +++ b/res/dist/media/materials/programs/varianceshadowcasterfp.glsles @@ -0,0 +1,132 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// varianceshadowcasterfp.glsles +// +// Hamilton Chong +// (c) 2006 +// GLSL ES by David Rogers +// +// This is an example fragment shader for shadow caster objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +// Define outputs from vertex shader. +struct VertexOut +{ + float4 position : POSITION; // can't rely on access to this + float4 pos : TEXCOORD0; // position of fragment (in homogeneous coordinates) + float4 normal : TEXCOORD1; // un-normalized normal in object space + float4 modelPos : TEXCOORD2; // coordinates of model in object space at this point +}; + +struct FragmentOut +{ + float4 color : COLOR0; +}; + +FragmentOut main( VertexOut In, // fragment to process + uniform float uDepthOffset, // offset amount (constant in eye space) + uniform float4x4 uProjection // projection matrix + ) +{ + FragmentOut Out; + + // compute the "normalized device coordinates" (no viewport applied yet) + float4 postproj = In.pos / In.pos.w; + + // get the normalized normal of the geometry seen at this point + float4 normal = normalize(In.normal); + + + // -- Computing Depth Bias Quantities ----------------------------- + + // We now compute the change in z that would signify a push in the z direction + // by 1 unit in eye space. Note that eye space z is related in a nonlinear way to + // screen space z, so this is not just a constant. + // ddepth below is how much screen space z at this point would change for that push. + // NOTE: computation of ddepth likely differs from OpenGL's glPolygonOffset "unit" + // computation, which is allowed to be vendor specific. + float4 dpwdz = mul(uProjection, float4(0.0, 0.0, 1.0, 0.0)); + float4 dpdz = (dpwdz - (postproj * dpwdz.w)) / In.pos.w; + float ddepth = abs(dpdz.z); + + // -- End depth bias helper section -------------------------------- + + // We now compute the depth of the fragment. This is the actual depth value plus + // our depth bias. The depth bias depends on how uncertain we are about the z value + // plus some constant push in the z direction. The exact coefficients to use are + // up to you, but at least it should be somewhat intuitive now what the tradeoffs are. + float depthval = postproj.z /* + (0.5 * dzlen)*/ + (uDepthOffset * ddepth); + depthval = (0.5 * depthval) + 0.5; // put into [0,1] range instead of [-1,1] + + + Out.color = float4(depthval, depthval * depthval, depthval, 0.0); + return Out; +} +///////////////////////////////////////////////////////////////////////////////// +// +// varianceshadowcasterfp.glsles +// +// Hamilton Chong +// (c) 2006 +// GLSL ES by David Rogers +// +// This is an example fragment shader for shadow caster objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +// Define outputs from vertex shader. +struct VertexOut +{ + float4 position : POSITION; // can't rely on access to this + float4 pos : TEXCOORD0; // position of fragment (in homogeneous coordinates) + float4 normal : TEXCOORD1; // un-normalized normal in object space + float4 modelPos : TEXCOORD2; // coordinates of model in object space at this point +}; + +struct FragmentOut +{ + float4 color : COLOR0; +}; + +FragmentOut main( VertexOut In, // fragment to process + uniform float uDepthOffset, // offset amount (constant in eye space) + uniform float4x4 uProjection // projection matrix + ) +{ + FragmentOut Out; + + // compute the "normalized device coordinates" (no viewport applied yet) + float4 postproj = In.pos / In.pos.w; + + // get the normalized normal of the geometry seen at this point + float4 normal = normalize(In.normal); + + + // -- Computing Depth Bias Quantities ----------------------------- + + // We now compute the change in z that would signify a push in the z direction + // by 1 unit in eye space. Note that eye space z is related in a nonlinear way to + // screen space z, so this is not just a constant. + // ddepth below is how much screen space z at this point would change for that push. + // NOTE: computation of ddepth likely differs from OpenGL's glPolygonOffset "unit" + // computation, which is allowed to be vendor specific. + float4 dpwdz = mul(uProjection, float4(0.0, 0.0, 1.0, 0.0)); + float4 dpdz = (dpwdz - (postproj * dpwdz.w)) / In.pos.w; + float ddepth = abs(dpdz.z); + + // -- End depth bias helper section -------------------------------- + + // We now compute the depth of the fragment. This is the actual depth value plus + // our depth bias. The depth bias depends on how uncertain we are about the z value + // plus some constant push in the z direction. The exact coefficients to use are + // up to you, but at least it should be somewhat intuitive now what the tradeoffs are. + float depthval = postproj.z /* + (0.5 * dzlen)*/ + (uDepthOffset * ddepth); + depthval = (0.5 * depthval) + 0.5; // put into [0,1] range instead of [-1,1] + + + Out.color = float4(depthval, depthval * depthval, depthval, 0.0); + return Out; +} diff --git a/res/dist/media/materials/programs/varianceshadowcastervp.cg b/res/dist/media/materials/programs/varianceshadowcastervp.cg new file mode 100644 index 00000000000..60d6de3a551 --- /dev/null +++ b/res/dist/media/materials/programs/varianceshadowcastervp.cg @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// shadowcastervp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example vertex shader for shadow caster objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +// Define inputs from application. +struct VertexIn +{ + float4 position : POSITION; // vertex position in object space + float4 normal : NORMAL; // vertex normal in object space +}; + +// Define outputs from vertex shader. +struct VertexOut +{ + float4 position : POSITION; // post projection position coordinates + float4 pos : TEXCOORD0; // ditto. Not all hardware allows access values bound to POSITION in fp. + float4 normal : TEXCOORD1; // normal in object space (to be interpolated) + float4 modelPos : TEXCOORD2; // position in object space (to be interpolated) +}; + +VertexOut main( VertexIn In, // vertex to process + uniform float4x4 uModelViewProjection // model-view-projection matrix + ) +{ + VertexOut Out; // output data + + // Transform vertex position into post projective (homogenous screen) space. + Out.position = mul(uModelViewProjection, In.position); + Out.pos = mul(uModelViewProjection, In.position); + + // copy over data to interpolate using perspective correct interpolation + Out.normal = float4(In.normal.x, In.normal.y, In.normal.z, 0.0); + Out.modelPos = In.position; + + return Out; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/varianceshadowcastervp.glsles b/res/dist/media/materials/programs/varianceshadowcastervp.glsles new file mode 100644 index 00000000000..3cf3715854d --- /dev/null +++ b/res/dist/media/materials/programs/varianceshadowcastervp.glsles @@ -0,0 +1,88 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// shadowcastervp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example vertex shader for shadow caster objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +// Define inputs from application. +struct VertexIn +{ + float4 position : POSITION; // vertex position in object space + float4 normal : NORMAL; // vertex normal in object space +}; + +// Define outputs from vertex shader. +struct VertexOut +{ + float4 position : POSITION; // post projection position coordinates + float4 pos : TEXCOORD0; // ditto. Not all hardware allows access values bound to POSITION in fp. + float4 normal : TEXCOORD1; // normal in object space (to be interpolated) + float4 modelPos : TEXCOORD2; // position in object space (to be interpolated) +}; + +VertexOut main( VertexIn In, // vertex to process + uniform float4x4 uModelViewProjection // model-view-projection matrix + ) +{ + VertexOut Out; // output data + + // Transform vertex position into post projective (homogenous screen) space. + Out.position = mul(uModelViewProjection, In.position); + Out.pos = mul(uModelViewProjection, In.position); + + // copy over data to interpolate using perspective correct interpolation + Out.normal = float4(In.normal.x, In.normal.y, In.normal.z, 0.0); + Out.modelPos = In.position; + + return Out; +} +///////////////////////////////////////////////////////////////////////////////// +// +// shadowcastervp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example vertex shader for shadow caster objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +// Define inputs from application. +struct VertexIn +{ + float4 position : POSITION; // vertex position in object space + float4 normal : NORMAL; // vertex normal in object space +}; + +// Define outputs from vertex shader. +struct VertexOut +{ + float4 position : POSITION; // post projection position coordinates + float4 pos : TEXCOORD0; // ditto. Not all hardware allows access values bound to POSITION in fp. + float4 normal : TEXCOORD1; // normal in object space (to be interpolated) + float4 modelPos : TEXCOORD2; // position in object space (to be interpolated) +}; + +VertexOut main( VertexIn In, // vertex to process + uniform float4x4 uModelViewProjection // model-view-projection matrix + ) +{ + VertexOut Out; // output data + + // Transform vertex position into post projective (homogenous screen) space. + Out.position = mul(uModelViewProjection, In.position); + Out.pos = mul(uModelViewProjection, In.position); + + // copy over data to interpolate using perspective correct interpolation + Out.normal = float4(In.normal.x, In.normal.y, In.normal.z, 0.0); + Out.modelPos = In.position; + + return Out; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/varianceshadowreceiverfp.cg b/res/dist/media/materials/programs/varianceshadowreceiverfp.cg new file mode 100644 index 00000000000..28a9aacfbfc --- /dev/null +++ b/res/dist/media/materials/programs/varianceshadowreceiverfp.cg @@ -0,0 +1,107 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// shadowreceiverfp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example fragment shader for shadow receiver objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +sampler2D ShadowMap : TEXUNIT0; + +// Define outputs from vertex shader. +struct Vertex +{ + float4 position : POSITION; // fragment position in post projective space + float4 shadowCoord : TEXCOORD0; // fragment position in shadow map coordinates + float diffuse : TEXCOORD1; // diffuse shading value +}; + +struct Fragment +{ + float4 color : COLOR0; +}; + +Fragment main(Vertex In, + uniform float uSTexWidth, + uniform float uSTexHeight) +{ + Fragment Out; + + // compute the shadow coordinates for texture lookup + // NOTE: texture_viewproj_matrix maps z into [0,1] range, not [-1,1], so + // have to make sure shadow caster stores depth values with same convention. + float4 scoord = In.shadowCoord / In.shadowCoord.w; + + + // -- Bilinear Filtering of Sample -------------------------------------------- + + // One could use scoord.xy to look up the shadow map for depth testing, but + // we'll be implementing a simple "percentage closest filtering" algorithm instead. + // This mimics the behavior of turning on bilinear filtering on NVIDIA hardware + // when also performing shadow comparisons. This causes bilinear filtering of + // depth tests. Note that this is NOT the same as bilinear filtering the depth + // values and then doing the depth comparison. The two operations are not + // commutative. PCF is explicitly about filtering the test values since + // testing filtered z values is often meaningless. + + // Real percentage closest filtering should sample from the entire footprint + // on the shadow map, not just seek the closest four sample points. Such + // an improvement is for future work. + + + // NOTE: Assuming OpenGL convention for texture lookups with integers in centers. + // DX convention is to have integers mark sample corners + float2 tcoord; + tcoord.x = (scoord.x * uSTexWidth) - 0.5; + tcoord.y = (scoord.y * uSTexHeight) - 0.5; + float x0 = floor(tcoord.x); + float x1 = ceil(tcoord.x); + float fracx = frac(tcoord.x); + float y0 = floor(tcoord.y); + float y1 = ceil(tcoord.y); + float fracy = frac(tcoord.y); + + // sample coordinates in [0,1]^2 domain + float2 t00, t01, t10, t11; + float invWidth = 1.0 / uSTexWidth; + float invHeight = 1.0 / uSTexHeight; + t00 = float2((x0+0.5) * invWidth, (y0+0.5) * invHeight); + t10 = float2((x1+0.5) * invWidth, (y0+0.5) * invHeight); + t01 = float2((x0+0.5) * invWidth, (y1+0.5) * invHeight); + t11 = float2((x1+0.5) * invWidth, (y1+0.5) * invHeight); + + // grab the samples + float2 z00 = tex2D(ShadowMap, t00).xy; + float2 z01 = tex2D(ShadowMap, t01).xy; + float2 z10 = tex2D(ShadowMap, t10).xy; + float2 z11 = tex2D(ShadowMap, t11).xy; + + // bilinear filter the sample data + float2 d0 = ((1.0 - fracx) * z00) + (fracx * z10); + float2 d1 = ((1.0 - fracx) * z01) + (fracx * z11); + float2 datum = ((1.0 - fracy) * d0) + (fracy * d1); + + // -- Variance Shadow Mapping --------------------------------------------------- + + float zVariance = datum.y - (datum.x * datum.x); + float zDeviation = scoord.z - datum.x; + zDeviation = (zDeviation < 0.0) ? 0.0 : zDeviation; + float visibility = zVariance / (zVariance + (zDeviation * zDeviation)); + float ztest = (scoord.z < datum.x) ? 1.0:0.0; // filtering depth ok, because used only for small variance + visibility = (zVariance > 0.0) ? visibility : ztest; // if variance too small, we get garbage + //0.0000001 + + // determine that all geometry within pixel border of shadow map (and outside) is lit + float filterBorder = max(invWidth, invHeight); + visibility = (all(abs(scoord.xy-0.5)<=0.5-filterBorder)) ? visibility : 1.0; + + // ------------------------------------------------------------------------------ + + visibility *= In.diffuse; + Out.color = float4(visibility, visibility, visibility, 0.0); + return Out; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/varianceshadowreceiverfp.glsles b/res/dist/media/materials/programs/varianceshadowreceiverfp.glsles new file mode 100644 index 00000000000..120700eebfc --- /dev/null +++ b/res/dist/media/materials/programs/varianceshadowreceiverfp.glsles @@ -0,0 +1,214 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// shadowreceiverfp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example fragment shader for shadow receiver objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +sampler2D ShadowMap : TEXUNIT0; + +// Define outputs from vertex shader. +struct Vertex +{ + float4 position : POSITION; // fragment position in post projective space + float4 shadowCoord : TEXCOORD0; // fragment position in shadow map coordinates + float diffuse : TEXCOORD1; // diffuse shading value +}; + +struct Fragment +{ + float4 color : COLOR0; +}; + +Fragment main(Vertex In, + uniform float uSTexWidth, + uniform float uSTexHeight) +{ + Fragment Out; + + // compute the shadow coordinates for texture lookup + // NOTE: texture_viewproj_matrix maps z into [0,1] range, not [-1,1], so + // have to make sure shadow caster stores depth values with same convention. + float4 scoord = In.shadowCoord / In.shadowCoord.w; + + + // -- Bilinear Filtering of Sample -------------------------------------------- + + // One could use scoord.xy to look up the shadow map for depth testing, but + // we'll be implementing a simple "percentage closest filtering" algorithm instead. + // This mimics the behavior of turning on bilinear filtering on NVIDIA hardware + // when also performing shadow comparisons. This causes bilinear filtering of + // depth tests. Note that this is NOT the same as bilinear filtering the depth + // values and then doing the depth comparison. The two operations are not + // commutative. PCF is explicitly about filtering the test values since + // testing filtered z values is often meaningless. + + // Real percentage closest filtering should sample from the entire footprint + // on the shadow map, not just seek the closest four sample points. Such + // an improvement is for future work. + + + // NOTE: Assuming OpenGL convention for texture lookups with integers in centers. + // DX convention is to have integers mark sample corners + float2 tcoord; + tcoord.x = (scoord.x * uSTexWidth) - 0.5; + tcoord.y = (scoord.y * uSTexHeight) - 0.5; + float x0 = floor(tcoord.x); + float x1 = ceil(tcoord.x); + float fracx = frac(tcoord.x); + float y0 = floor(tcoord.y); + float y1 = ceil(tcoord.y); + float fracy = frac(tcoord.y); + + // sample coordinates in [0,1]^2 domain + float2 t00, t01, t10, t11; + float invWidth = 1.0 / uSTexWidth; + float invHeight = 1.0 / uSTexHeight; + t00 = float2((x0+0.5) * invWidth, (y0+0.5) * invHeight); + t10 = float2((x1+0.5) * invWidth, (y0+0.5) * invHeight); + t01 = float2((x0+0.5) * invWidth, (y1+0.5) * invHeight); + t11 = float2((x1+0.5) * invWidth, (y1+0.5) * invHeight); + + // grab the samples + float2 z00 = tex2D(ShadowMap, t00).xy; + float2 z01 = tex2D(ShadowMap, t01).xy; + float2 z10 = tex2D(ShadowMap, t10).xy; + float2 z11 = tex2D(ShadowMap, t11).xy; + + // bilinear filter the sample data + float2 d0 = ((1.0 - fracx) * z00) + (fracx * z10); + float2 d1 = ((1.0 - fracx) * z01) + (fracx * z11); + float2 datum = ((1.0 - fracy) * d0) + (fracy * d1); + + // -- Variance Shadow Mapping --------------------------------------------------- + + float zVariance = datum.y - (datum.x * datum.x); + float zDeviation = scoord.z - datum.x; + zDeviation = (zDeviation < 0.0) ? 0.0 : zDeviation; + float visibility = zVariance / (zVariance + (zDeviation * zDeviation)); + float ztest = (scoord.z < datum.x) ? 1.0:0.0; // filtering depth ok, because used only for small variance + visibility = (zVariance > 0.0) ? visibility : ztest; // if variance too small, we get garbage + //0.0000001 + + // determine that all geometry within pixel border of shadow map (and outside) is lit + float filterBorder = max(invWidth, invHeight); + visibility = (all(abs(scoord.xy-0.5)<=0.5-filterBorder)) ? visibility : 1.0; + + // ------------------------------------------------------------------------------ + + visibility *= In.diffuse; + Out.color = float4(visibility, visibility, visibility, 0.0); + return Out; +} +///////////////////////////////////////////////////////////////////////////////// +// +// shadowreceiverfp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example fragment shader for shadow receiver objects. +// +///////////////////////////////////////////////////////////////////////////////// + + +sampler2D ShadowMap : TEXUNIT0; + +// Define outputs from vertex shader. +struct Vertex +{ + float4 position : POSITION; // fragment position in post projective space + float4 shadowCoord : TEXCOORD0; // fragment position in shadow map coordinates + float diffuse : TEXCOORD1; // diffuse shading value +}; + +struct Fragment +{ + float4 color : COLOR0; +}; + +Fragment main(Vertex In, + uniform float uSTexWidth, + uniform float uSTexHeight) +{ + Fragment Out; + + // compute the shadow coordinates for texture lookup + // NOTE: texture_viewproj_matrix maps z into [0,1] range, not [-1,1], so + // have to make sure shadow caster stores depth values with same convention. + float4 scoord = In.shadowCoord / In.shadowCoord.w; + + + // -- Bilinear Filtering of Sample -------------------------------------------- + + // One could use scoord.xy to look up the shadow map for depth testing, but + // we'll be implementing a simple "percentage closest filtering" algorithm instead. + // This mimics the behavior of turning on bilinear filtering on NVIDIA hardware + // when also performing shadow comparisons. This causes bilinear filtering of + // depth tests. Note that this is NOT the same as bilinear filtering the depth + // values and then doing the depth comparison. The two operations are not + // commutative. PCF is explicitly about filtering the test values since + // testing filtered z values is often meaningless. + + // Real percentage closest filtering should sample from the entire footprint + // on the shadow map, not just seek the closest four sample points. Such + // an improvement is for future work. + + + // NOTE: Assuming OpenGL convention for texture lookups with integers in centers. + // DX convention is to have integers mark sample corners + float2 tcoord; + tcoord.x = (scoord.x * uSTexWidth) - 0.5; + tcoord.y = (scoord.y * uSTexHeight) - 0.5; + float x0 = floor(tcoord.x); + float x1 = ceil(tcoord.x); + float fracx = frac(tcoord.x); + float y0 = floor(tcoord.y); + float y1 = ceil(tcoord.y); + float fracy = frac(tcoord.y); + + // sample coordinates in [0,1]^2 domain + float2 t00, t01, t10, t11; + float invWidth = 1.0 / uSTexWidth; + float invHeight = 1.0 / uSTexHeight; + t00 = float2((x0+0.5) * invWidth, (y0+0.5) * invHeight); + t10 = float2((x1+0.5) * invWidth, (y0+0.5) * invHeight); + t01 = float2((x0+0.5) * invWidth, (y1+0.5) * invHeight); + t11 = float2((x1+0.5) * invWidth, (y1+0.5) * invHeight); + + // grab the samples + float2 z00 = tex2D(ShadowMap, t00).xy; + float2 z01 = tex2D(ShadowMap, t01).xy; + float2 z10 = tex2D(ShadowMap, t10).xy; + float2 z11 = tex2D(ShadowMap, t11).xy; + + // bilinear filter the sample data + float2 d0 = ((1.0 - fracx) * z00) + (fracx * z10); + float2 d1 = ((1.0 - fracx) * z01) + (fracx * z11); + float2 datum = ((1.0 - fracy) * d0) + (fracy * d1); + + // -- Variance Shadow Mapping --------------------------------------------------- + + float zVariance = datum.y - (datum.x * datum.x); + float zDeviation = scoord.z - datum.x; + zDeviation = (zDeviation < 0.0) ? 0.0 : zDeviation; + float visibility = zVariance / (zVariance + (zDeviation * zDeviation)); + float ztest = (scoord.z < datum.x) ? 1.0:0.0; // filtering depth ok, because used only for small variance + visibility = (zVariance > 0.0) ? visibility : ztest; // if variance too small, we get garbage + //0.0000001 + + // determine that all geometry within pixel border of shadow map (and outside) is lit + float filterBorder = max(invWidth, invHeight); + visibility = (all(abs(scoord.xy-0.5)<=0.5-filterBorder)) ? visibility : 1.0; + + // ------------------------------------------------------------------------------ + + visibility *= In.diffuse; + Out.color = float4(visibility, visibility, visibility, 0.0); + return Out; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/varianceshadowreceivervp.cg b/res/dist/media/materials/programs/varianceshadowreceivervp.cg new file mode 100644 index 00000000000..ff950405ca3 --- /dev/null +++ b/res/dist/media/materials/programs/varianceshadowreceivervp.cg @@ -0,0 +1,47 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// shadowreceivervp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example vertex shader for shadow receiver objects. +// +///////////////////////////////////////////////////////////////////////////////// + +// Define inputs from application. +struct VertexIn +{ + float4 position : POSITION; // vertex position in object space + float4 normal : NORMAL; // vertex normal in object space +}; + +// Define outputs from vertex shader. +struct Vertex +{ + float4 position : POSITION; // vertex position in post projective space + float4 shadowCoord : TEXCOORD0; // vertex position in shadow map coordinates + float diffuse : TEXCOORD1; // diffuse shading value +}; + +Vertex main(VertexIn In, + uniform float4x4 uModelViewProjection, // model-view-projection matrix + uniform float4 uLightPosition, // light position in object space + uniform float4x4 uModel, // model matrix + uniform float4x4 uTextureViewProjection // shadow map's view projection matrix + ) +{ + Vertex Out; + + // compute diffuse shading + float3 lightDirection = normalize(uLightPosition.xyz - In.position.xyz); + Out.diffuse = dot(In.normal.xyz, lightDirection); + + // compute shadow map lookup coordinates + Out.shadowCoord = mul(uTextureViewProjection, mul(uModel, In.position)); + + // compute vertex's homogenous screen-space coordinates + Out.position = mul(uModelViewProjection, In.position); + + return Out; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/varianceshadowreceivervp.glsles b/res/dist/media/materials/programs/varianceshadowreceivervp.glsles new file mode 100644 index 00000000000..e88c0e98f6b --- /dev/null +++ b/res/dist/media/materials/programs/varianceshadowreceivervp.glsles @@ -0,0 +1,94 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// shadowreceivervp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example vertex shader for shadow receiver objects. +// +///////////////////////////////////////////////////////////////////////////////// + +// Define inputs from application. +struct VertexIn +{ + float4 position : POSITION; // vertex position in object space + float4 normal : NORMAL; // vertex normal in object space +}; + +// Define outputs from vertex shader. +struct Vertex +{ + float4 position : POSITION; // vertex position in post projective space + float4 shadowCoord : TEXCOORD0; // vertex position in shadow map coordinates + float diffuse : TEXCOORD1; // diffuse shading value +}; + +Vertex main(VertexIn In, + uniform float4x4 uModelViewProjection, // model-view-projection matrix + uniform float4 uLightPosition, // light position in object space + uniform float4x4 uModel, // model matrix + uniform float4x4 uTextureViewProjection // shadow map's view projection matrix + ) +{ + Vertex Out; + + // compute diffuse shading + float3 lightDirection = normalize(uLightPosition.xyz - In.position.xyz); + Out.diffuse = dot(In.normal.xyz, lightDirection); + + // compute shadow map lookup coordinates + Out.shadowCoord = mul(uTextureViewProjection, mul(uModel, In.position)); + + // compute vertex's homogenous screen-space coordinates + Out.position = mul(uModelViewProjection, In.position); + + return Out; +} +///////////////////////////////////////////////////////////////////////////////// +// +// shadowreceivervp.cg +// +// Hamilton Chong +// (c) 2006 +// +// This is an example vertex shader for shadow receiver objects. +// +///////////////////////////////////////////////////////////////////////////////// + +// Define inputs from application. +struct VertexIn +{ + float4 position : POSITION; // vertex position in object space + float4 normal : NORMAL; // vertex normal in object space +}; + +// Define outputs from vertex shader. +struct Vertex +{ + float4 position : POSITION; // vertex position in post projective space + float4 shadowCoord : TEXCOORD0; // vertex position in shadow map coordinates + float diffuse : TEXCOORD1; // diffuse shading value +}; + +Vertex main(VertexIn In, + uniform float4x4 uModelViewProjection, // model-view-projection matrix + uniform float4 uLightPosition, // light position in object space + uniform float4x4 uModel, // model matrix + uniform float4x4 uTextureViewProjection // shadow map's view projection matrix + ) +{ + Vertex Out; + + // compute diffuse shading + float3 lightDirection = normalize(uLightPosition.xyz - In.position.xyz); + Out.diffuse = dot(In.normal.xyz, lightDirection); + + // compute shadow map lookup coordinates + Out.shadowCoord = mul(uTextureViewProjection, mul(uModel, In.position)); + + // compute vertex's homogenous screen-space coordinates + Out.position = mul(uModelViewProjection, In.position); + + return Out; +} \ No newline at end of file diff --git a/res/dist/media/materials/scripts/ASCII.material b/res/dist/media/materials/scripts/ASCII.material new file mode 100644 index 00000000000..27318995d1e --- /dev/null +++ b/res/dist/media/materials/scripts/ASCII.material @@ -0,0 +1,55 @@ +fragment_program Ogre/Compositor/ASCIIFP cg +{ + source ASCIIFP.cg + entry_point ASCII_ps + profiles ps_4_0 ps_2_0 arbfp1 + + default_params + { + param_named iNumTiles float2 0.010 0.02 + param_named iNumTiles2 float2 0.005 0.01 + param_named numTiles float2 100 50 + param_named lum float4 0.30 0.59 0.11 0.0 + param_named charBias float 0.734375 + } +} + +material Ogre/Compositor/ASCII +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + + fragment_program_ref Ogre/Compositor/ASCIIFP + { + + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + texture_unit chars + { + texture ASCII.dds 3d + filtering none + tex_address_mode clamp + } + + } + } +} + diff --git a/res/dist/media/materials/scripts/ASMSwizzle.material b/res/dist/media/materials/scripts/ASMSwizzle.material new file mode 100644 index 00000000000..b55e0995baf --- /dev/null +++ b/res/dist/media/materials/scripts/ASMSwizzle.material @@ -0,0 +1,19 @@ +geometry_program Ogre/GPTest/Swizzle_GP_ASM asm +{ + source Swizzle.gp + syntax nvgp4 +} + +material Ogre/GPTest/SwizzleASM +{ + technique SwizzleTechnique + { + pass SwizzleASMPass + { + geometry_program_ref Ogre/GPTest/Swizzle_GP_ASM + { + + } + } + } +} diff --git a/res/dist/media/materials/scripts/BlackAndWhite.material b/res/dist/media/materials/scripts/BlackAndWhite.material new file mode 100644 index 00000000000..9a78efdd2d9 --- /dev/null +++ b/res/dist/media/materials/scripts/BlackAndWhite.material @@ -0,0 +1,45 @@ +fragment_program Ogre/Compositor/B&W_Cg_FP cg +{ + source GrayScale.cg + entry_point GrayScale_ps + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/B&W_GLSLES_FP glsles +{ + source GrayScale.glsles +} + +fragment_program Ogre/Compositor/B&W_FP unified +{ + delegate Ogre/Compositor/B&W_GLSLES_FP + delegate Ogre/Compositor/B&W_Cg_FP +} + +material Ogre/Compositor/BlackAndWhite +{ + technique + { + + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp + { + } + + fragment_program_ref Ogre/Compositor/B&W_FP + { + } + + texture_unit + { + texture RT + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + } + } +} diff --git a/res/dist/media/materials/scripts/Bloom.material b/res/dist/media/materials/scripts/Bloom.material new file mode 100644 index 00000000000..6b9f59637b4 --- /dev/null +++ b/res/dist/media/materials/scripts/Bloom.material @@ -0,0 +1,217 @@ +//DirectX 9.0 HLSL Vertex Shader vs_1_1 +vertex_program Blur0_vs11 hlsl +{ + source Blur0_vs11.hlsl + target vs_1_1 + entry_point main +} + +//DirectX 9.0 HLSL Pixel Shader ps_2_0 +fragment_program Blur0_ps20 hlsl +{ + source Blur0_ps20.hlsl + target ps_2_0 + entry_point main +} + +//DirectX 9.0 HLSL Vertex Shader vs_1_1 +vertex_program Blur1_vs11 hlsl +{ + source Blur1_vs11.hlsl + target vs_1_1 + entry_point main +} + +//DirectX 9.0 HLSL Pixel Shader ps_2_0 +fragment_program Blur1_ps20 hlsl +{ + source Blur1_ps20.hlsl + target ps_2_0 + entry_point main +} + +vertex_program Blur0_vs_glsl glsl +{ + source Blur0_vs.glsl +} +vertex_program Blur1_vs_glsl glsl +{ + source Blur1_vs.glsl +} +fragment_program Blur_ps_glsl glsl +{ + source Blur_ps.glsl + default_params + { + param_named tex0 int 0 + } +} + +vertex_program Blur0_vs_glsles glsles +{ + source Blur0_vs.glsles +} +vertex_program Blur1_vs_glsles glsles +{ + source Blur1_vs.glsles +} +fragment_program Blur_ps_glsles glsles +{ + source Blur_ps.glsles + default_params + { + param_named tex0 int 0 + } +} + +//------------------------ +//Unified Definitions +//------------------------ +vertex_program Blur0_vs_gl_unified unified +{ + delegate Blur0_vs_glsl + delegate Blur0_vs_glsles +} + +vertex_program Blur1_vs_gl_unified unified +{ + delegate Blur1_vs_glsl + delegate Blur1_vs_glsles +} + +fragment_program Blur_ps_gl_unified unified +{ + delegate Blur_ps_glsl + delegate Blur_ps_glsles +} + + +//Effect: Bloom +material Ogre/Compositor/Blur0 +{ + technique + { + //Rendering Pass: Blur0 (pass index: #1 ) + pass + { + //State: D3DRS_CULLMODE, Value : D3DCULL_NONE + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref Blur0_ps20 + { + } + vertex_program_ref Blur0_vs11 + { + } + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + } + } + technique + { + //Rendering Pass: Blur0 (pass index: #1 ) + pass + { + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref Blur_ps_gl_unified + { + } + vertex_program_ref Blur0_vs_gl_unified + { + } + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + } + } +} + +material Ogre/Compositor/Blur1 +{ + technique + { + + //Rendering Pass: Blur1 (pass index: #2 ) + pass + { + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref Blur1_ps20 + { + } + vertex_program_ref Blur1_vs11 + { + } + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + } + } + technique + { + + //Rendering Pass: Blur1 (pass index: #2 ) + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + fragment_program_ref Blur_ps_gl_unified + { + } + vertex_program_ref Blur1_vs_gl_unified + { + } + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + } + } +} + +/// Overlay quad +material Ogre/Compositor/BloomBlend +{ + technique + { + pass + { + lighting on + diffuse 0.0 0.0 0.0 0.6 + specular 0.0 0.0 0.0 0.0 + ambient 0.0 0.0 0.0 + emissive 1.0 1.0 1.0 + cull_hardware none + depth_check off + scene_blend alpha_blend + + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + } + } +} diff --git a/res/dist/media/materials/scripts/Bloom2.material b/res/dist/media/materials/scripts/Bloom2.material new file mode 100644 index 00000000000..ef02ba7d0b8 --- /dev/null +++ b/res/dist/media/materials/scripts/Bloom2.material @@ -0,0 +1,360 @@ +//--------------------------------------------------- +//Bloom2: Dark Sylinc's Bloom implementation +// Ogre/Compositor/BloomBlend is the final material applied. +// it has 2 parameters: +// OriginalImageWeight float +// BlurWeight float +// Usually they range from 0.0 to 1.0; but it can be any number +// higher numbers will result in a brighter scene. Increment BlurWeight +// to obtain increase Bloom effect. +// Works faster on my GeForce 6200 256 MB AGP 8x (Chip NV 43 Rev a1) +// than Manuel's bloom. (And at my opinion, looks nicer ;) +// Unlike Manuel's bloom, we apply a bright high-filter pass +//Copyright (C) Dark Sylinc 2007-2008 +//--------------------------------------------------- + +// NB not using GLSL versions since ATI GLSL compiler has a problem with +// BlurV_ps20 +//------------------------ +//OpenGL GLSL Definitions +//------------------------ +vertex_program Blur_vs_glsl glsl +{ + source Blur_vs.glsl +} +fragment_program BlurV_ps20_glsl glsl +{ + source BlurV_ps20.glsl +} +fragment_program BlurH_ps20_glsl glsl +{ + source BlurH_ps20.glsl +} +fragment_program BrightBloom2_ps20_glsl glsl +{ + source BrightBloom2_ps20.glsl +} +fragment_program Bloom2_ps20_glsl glsl +{ + source Bloom2_ps20.glsl + default_params + { + param_named RT int 0 + param_named Blur1 int 1 + } +} + +//------------------------ +//OpenGL GLSL ES Definitions +//------------------------ +vertex_program Blur_vs_glsles glsles +{ + source Blur_vs.glsles +} +fragment_program BlurV_ps20_glsles glsles +{ + source BlurV_ps20.glsles +} +fragment_program BlurH_ps20_glsles glsles +{ + source BlurH_ps20.glsles +} +fragment_program BrightBloom2_ps20_glsles glsles +{ + source BrightBloom2_ps20.glsles +} +fragment_program Bloom2_ps20_glsles glsles +{ + source Bloom2_ps20.glsles + default_params + { + param_named RT int 0 + param_named Blur1 int 1 + } +} + +//------------------------ +//DirectX 9.0 HLSL Definitions +//------------------------ +//DirectX 9.0 HLSL Vertex Shader vs_1_1 +vertex_program Blur_vs11_hlsl hlsl +{ + source Blur_vs11.hlsl + target vs_1_1 + entry_point main +} + +//DirectX 9.0 HLSL Pixel Shader ps_2_0 +fragment_program BlurV_ps20_hlsl hlsl +{ + source BlurV_ps20.hlsl + target ps_2_0 + entry_point main +} +fragment_program BlurH_ps20_hlsl hlsl +{ + source BlurH_ps20.hlsl + target ps_2_0 + entry_point main +} + +//DirectX 9.0 HLSL Pixel Shader ps_2_0 +fragment_program Bloom2_ps20_hlsl hlsl +{ + source Bloom2_ps20.hlsl + target ps_2_0 + entry_point main +} + +//DirectX 9.0 HLSL Pixel Shader ps_2_0 +fragment_program BrightBloom2_ps20_hlsl hlsl +{ + source BrightBloom2_ps20.hlsl + target ps_2_0 + entry_point main +} + +//------------------------ +//DirectX 11 HLSL Definitions +//------------------------ +//DirectX 11 HLSL Vertex Shader vs_4_0 +vertex_program Blur_vs40_hlsl hlsl +{ + source Blur_vs40.hlsl + target vs_4_0 + entry_point main +} + +//DirectX 11 HLSL Pixel Shader ps_4_0 +fragment_program BlurV_ps40_hlsl hlsl +{ + source BlurV_ps40.hlsl + target ps_4_0 + entry_point main +} +fragment_program BlurH_ps40_hlsl hlsl +{ + source BlurH_ps40.hlsl + target ps_4_0 + entry_point main +} + +//DirectX 11 HLSL Pixel Shader ps_4_0 +fragment_program Bloom2_ps40_hlsl hlsl +{ + source Bloom2_ps40.hlsl + target ps_4_0 + entry_point main +} + +//DirectX 11 HLSL Pixel Shader ps_4_0 +fragment_program BrightBloom2_ps40_hlsl hlsl +{ + source BrightBloom2_ps40.hlsl + target ps_4_0 + entry_point main +} + +//------------------------ +//NVIDIA Cg Definitions +//------------------------ +//NV Cg Vertex Shader vs_1_1 +vertex_program Blur_vs11_cg cg +{ + source Blur_vs11.hlsl + profiles vs_1_1 arbvp1 + entry_point main +} + +//NV Cg HLSL Pixel Shader ps_2_0 +fragment_program BlurV_ps20_cg cg +{ + source BlurV_ps20.hlsl + profiles ps_2_0 arbfp1 + entry_point main +} +fragment_program BlurH_ps20_cg cg +{ + source BlurH_ps20.hlsl + profiles ps_2_0 arbfp1 + entry_point main +} + +//NV Cg Pixel Shader ps_2_0 +fragment_program Bloom2_ps20_cg cg +{ + source Bloom2_ps20.hlsl + profiles ps_2_0 arbfp1 + entry_point main +} + +//NV Cg Pixel Shader ps_2_0 +fragment_program BrightBloom2_ps20_cg cg +{ + source BrightBloom2_ps20.hlsl + profiles ps_2_0 arbfp1 + entry_point main +} + +//------------------------ +//Unified Definitions +//------------------------ +vertex_program Blur_vs unified +{ + delegate Blur_vs11_hlsl + delegate Blur_vs40_hlsl + //delegate Blur_vs_glsl + delegate Blur_vs_glsles + delegate Blur_vs11_cg +} + +fragment_program Bloom2_ps unified +{ + delegate Bloom2_ps20_hlsl + delegate Bloom2_ps40_hlsl + //delegate Bloom2_ps20_glsl + delegate Bloom2_ps20_glsles + delegate Bloom2_ps20_cg +} +fragment_program BlurV_ps unified +{ + delegate BlurV_ps20_hlsl + delegate BlurV_ps40_hlsl + //delegate BlurV_ps20_glsl + delegate BlurV_ps20_glsles + delegate BlurV_ps20_cg +} +fragment_program BlurH_ps unified +{ + delegate BlurH_ps20_hlsl + delegate BlurH_ps40_hlsl + //delegate BlurH_ps20_glsl + delegate BlurH_ps20_glsles + delegate BlurH_ps20_cg +} +fragment_program BrightBloom2_ps unified +{ + delegate BrightBloom2_ps20_hlsl + delegate BrightBloom2_ps40_hlsl + delegate BrightBloom2_ps20_glsles + delegate BrightBloom2_ps20_cg +} + + +//Blur: Horizontal Gaussian pass +material Ogre/Compositor/BlurH +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref BlurH_ps + { + } + vertex_program_ref Blur_vs + { + } + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + } + } +} + +//Blur: Vertical Gaussian pass +material Ogre/Compositor/BlurV +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref BlurV_ps + { + } + vertex_program_ref Blur_vs + { + } + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + } + } +} + +//Final Bloom pass: Blends the blurred with the sharp image +material Ogre/Compositor/BloomBlend2 +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref Bloom2_ps + { + param_named OriginalImageWeight float 1.0 + param_named BlurWeight float 0.65 + } + vertex_program_ref Blur_vs + { + } + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering none + } + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + } + } +} + +//High-pass Bright filter +//First pass +material Ogre/Compositor/BrightPass2 +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref BrightBloom2_ps + { + } + + vertex_program_ref Ogre/Compositor/StdQuad_vp + { + } + + texture_unit + { + tex_address_mode clamp + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/CGSwizzle.material b/res/dist/media/materials/scripts/CGSwizzle.material new file mode 100644 index 00000000000..8d78b28e212 --- /dev/null +++ b/res/dist/media/materials/scripts/CGSwizzle.material @@ -0,0 +1,20 @@ +geometry_program Ogre/GPTest/Swizzle_GP_CG cg +{ + source SwizzleGP.cg + entry_point gs_swizzle + profiles gp4gp gpu_gp +} + +material Ogre/GPTest/SwizzleCG +{ + technique + { + pass SwizzleCGPass + { + geometry_program_ref Ogre/GPTest/Swizzle_GP_CG + { + + } + } + } +} \ No newline at end of file diff --git a/res/dist/media/materials/scripts/CompositorDemo.material b/res/dist/media/materials/scripts/CompositorDemo.material new file mode 100644 index 00000000000..d62f896ebbf --- /dev/null +++ b/res/dist/media/materials/scripts/CompositorDemo.material @@ -0,0 +1,18 @@ +material CompositorDemo/DebugView +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_check off + + texture_unit + { + //Will be filled by code, need to set specific on runtime + } + } + } + +} \ No newline at end of file diff --git a/res/dist/media/materials/scripts/DOF.material b/res/dist/media/materials/scripts/DOF.material new file mode 100644 index 00000000000..4cf819b3036 --- /dev/null +++ b/res/dist/media/materials/scripts/DOF.material @@ -0,0 +1,94 @@ +fragment_program DOF_Blur_ps cg +{ + source DOF_ps.cg + entry_point blur + profiles ps_2_0 arbfp1 +} + +fragment_program DOF_Blend_ps cg +{ + source DOF_ps.cg + entry_point blend + profiles ps_2_0 arbfp1 +} + +//Effect: Depth of Field +material Ogre/Compositor/DOF_Blur0 +{ + technique + { + //Rendering Pass: Blur0 (pass index: #1 ) + pass + { + //State: D3DRS_CULLMODE, Value : D3DCULL_NONE + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref DOF_Blur_ps + { + param_named sampleDistance float 0.1 + } + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + texture_unit + { + // texture will get added at runtime + tex_coord_set 0 + tex_address_mode wrap + filtering trilinear + } + } + } +} + +// cheat here by copying from DOF_Blur0 +material Ogre/Compositor/DOF_Blur1 : Ogre/Compositor/DOF_Blur0 +{ + technique + { + //Rendering Pass: Blur0 (pass index: #1 ) + pass + { + // use the same pixel shader as DOF_Blur0 + //fragment_program_ref + //{ + // override value from copied DOF_Blur0 material + // param_named sampleDistance float 0.1 + //} + } + } +} + +material Ogre/Compositor/DOF_Blend +{ + technique + { + pass + { + fragment_program_ref DOF_Blend_ps + { + param_named focus float 0.66 + param_named range float 1.0 + } + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + texture_unit Blur0 + { + // texture will get added at runtime + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + texture_unit Blur1 + { + // texture will get added at runtime + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + } + } +} diff --git a/res/dist/media/materials/scripts/DepthShadowmap.material b/res/dist/media/materials/scripts/DepthShadowmap.material new file mode 100644 index 00000000000..33d1f7e987b --- /dev/null +++ b/res/dist/media/materials/scripts/DepthShadowmap.material @@ -0,0 +1,747 @@ + +// ***-- Begin HLSL section --** + +vertex_program Ogre/DepthShadowmap/CasterVP_HLSL hlsl +{ + source DepthShadowmap.hlsl + entry_point casterVP + target vs_2_0 + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texelOffsets texel_offsets + //param_named_auto depthRange scene_depth_range + } +} + + +fragment_program Ogre/DepthShadowmap/CasterFP_HLSL hlsl +{ + source DepthShadowmap.hlsl + entry_point casterFP + target ps_2_0 + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + } +} + + +vertex_program Ogre/DepthShadowmap/ReceiverVP_HLSL hlsl +{ + source DepthShadowmap.hlsl + entry_point receiverVP + target vs_2_0 + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto world world_matrix + param_named_auto worldIT inverse_transpose_world_matrix + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texViewProj texture_viewproj_matrix + param_named_auto lightPosition light_position 0 + param_named_auto lightColour light_diffuse_colour 0 + //param_named_auto shadowDepthRange shadow_scene_depth_range 0 + } +} + + +fragment_program Ogre/DepthShadowmap/ReceiverFP_HLSL hlsl +{ + source DepthShadowmap.hlsl + entry_point receiverFP + target ps_2_0 + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=0 + + default_params + { + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + } +} + +fragment_program Ogre/DepthShadowmap/ReceiverFPPCF_HLSL hlsl +{ + source DepthShadowmap.hlsl + entry_point receiverFP + target ps_2_0 + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=1 + + default_params + { + param_named inverseShadowmapSize float 0.0009765625 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + } +} +vertex_program Ogre/DepthShadowmap/NormalMapReceiverVP_HLSL hlsl +{ + source DepthShadowmap.hlsl + entry_point normalMapShadowReceiverVp + target vs_2_0 + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto world world_matrix + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texViewProj texture_viewproj_matrix + param_named_auto lightPosition light_position_object_space 0 + //param_named_auto shadowDepthRange shadow_scene_depth_range 0 + } +} + +fragment_program Ogre/DepthShadowmap/NormalMapReceiverFP_HLSL hlsl +{ + source DepthShadowmap.hlsl + entry_point normalMapShadowReceiverFp + target ps_2_0 + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=0 + + default_params + { + param_named_auto lightColour light_diffuse_colour 0 + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + } +} +fragment_program Ogre/DepthShadowmap/NormalMapReceiverFPPCF_HLSL hlsl +{ + source DepthShadowmap.hlsl + entry_point normalMapShadowReceiverFp + target ps_2_0 + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=1 + + default_params + { + param_named_auto lightColour light_diffuse_colour 0 + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + } +} + + + +// **-- End HLSL Section --** + +// **-- Begin GLSL Section --** +vertex_program Ogre/DepthShadowmap/CasterVP_GLSL glsl +{ + source DepthShadowmapCasterVp.glsl + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texelOffsets texel_offsets + //param_named_auto depthRange scene_depth_range + } +} + + +fragment_program Ogre/DepthShadowmap/CasterFP_GLSL glsl +{ + source DepthShadowmapCasterFp.glsl + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + } +} + + +vertex_program Ogre/DepthShadowmap/ReceiverVP_GLSL glsl +{ + source DepthShadowmapReceiverVp.glsl + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto world world_matrix + param_named_auto worldIT inverse_transpose_world_matrix + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texViewProj texture_viewproj_matrix + param_named_auto lightPosition light_position 0 + param_named_auto lightColour light_diffuse_colour 0 + //param_named_auto shadowDepthRange shadow_scene_depth_range 0 + } +} + + +fragment_program Ogre/DepthShadowmap/ReceiverFP_GLSL glsl +{ + source DepthShadowmapReceiverFp.glsl + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=0 + + default_params + { + param_named shadowMap int 0 + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + } +} + +fragment_program Ogre/DepthShadowmap/ReceiverFPPCF_GLSL glsl +{ + source DepthShadowmapReceiverFp.glsl + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=1 + + default_params + { + param_named inverseShadowmapSize float 0.0009765625 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + } +} +vertex_program Ogre/DepthShadowmap/NormalMapReceiverVP_GLSL glsl +{ + source DepthShadowmapNormalMapReceiverVp.glsl + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto world world_matrix + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texViewProj texture_viewproj_matrix + param_named_auto lightPosition light_position_object_space 0 + //param_named_auto shadowDepthRange shadow_scene_depth_range 0 + } +} + +fragment_program Ogre/DepthShadowmap/NormalMapReceiverFP_GLSL glsl +{ + source DepthShadowmapNormalMapReceiverFp.glsl + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=0 + + default_params + { + param_named_auto lightColour light_diffuse_colour 0 + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + + param_named shadowMap int 0 + param_named normalMap int 1 + } +} +fragment_program Ogre/DepthShadowmap/NormalMapReceiverFPPCF_GLSL glsl +{ + source DepthShadowmapNormalMapReceiverFp.glsl + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=1 + + default_params + { + param_named_auto lightColour light_diffuse_colour 0 + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + + param_named shadowMap int 0 + param_named normalMap int 1 + } +} + +// **-- End GLSL Section --** + +// **-- Begin GLSL ES Section --** +vertex_program Ogre/DepthShadowmap/CasterVP_GLSLES glsles +{ + source DepthShadowmapCasterVp.glsles + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texelOffsets texel_offsets + //param_named_auto depthRange scene_depth_range + } +} + + +fragment_program Ogre/DepthShadowmap/CasterFP_GLSLES glsles +{ + source DepthShadowmapCasterFp.glsles + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + } +} + + +vertex_program Ogre/DepthShadowmap/ReceiverVP_GLSLES glsles +{ + source DepthShadowmapReceiverVp.glsles + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto world world_matrix + param_named_auto worldIT inverse_transpose_world_matrix + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texViewProj texture_viewproj_matrix + param_named_auto lightPosition light_position 0 + param_named_auto lightColour light_diffuse_colour 0 + //param_named_auto shadowDepthRange shadow_scene_depth_range 0 + } +} + + +fragment_program Ogre/DepthShadowmap/ReceiverFP_GLSLES glsles +{ + source DepthShadowmapReceiverFp.glsles + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=0 + + default_params + { + param_named shadowMap int 0 + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + } +} + +fragment_program Ogre/DepthShadowmap/ReceiverFPPCF_GLSLES glsles +{ + source DepthShadowmapReceiverFp.glsles + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=1 + + default_params + { + param_named inverseShadowmapSize float 0.0009765625 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + } +} +vertex_program Ogre/DepthShadowmap/NormalMapReceiverVP_GLSLES glsles +{ + source DepthShadowmapNormalMapReceiverVp.glsles + + preprocessor_defines LINEAR_RANGE=0 + + default_params + { + param_named_auto world world_matrix + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texViewProj texture_viewproj_matrix + param_named_auto lightPosition light_position_object_space 0 + //param_named_auto shadowDepthRange shadow_scene_depth_range 0 + } +} + +fragment_program Ogre/DepthShadowmap/NormalMapReceiverFP_GLSLES glsles +{ + source DepthShadowmapNormalMapReceiverFp.glsles + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=0 + + default_params + { + param_named_auto lightColour light_diffuse_colour 0 + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + + param_named shadowMap int 0 + param_named normalMap int 1 + } +} +fragment_program Ogre/DepthShadowmap/NormalMapReceiverFPPCF_GLSLES glsles +{ + source DepthShadowmapNormalMapReceiverFp.glsles + + preprocessor_defines LINEAR_RANGE=0,FUZZY_TEST=0,PCF=1 + + default_params + { + param_named_auto lightColour light_diffuse_colour 0 + param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + //param_named shadowFuzzyWidth float 1 + + param_named shadowMap int 0 + param_named normalMap int 1 + } +} + +// **-- End GLSL ES Section --** + +// **-- Begin Unified Section --** +vertex_program Ogre/DepthShadowmap/CasterVP unified +{ + delegate Ogre/DepthShadowmap/CasterVP_GLSL + delegate Ogre/DepthShadowmap/CasterVP_GLSLES + delegate Ogre/DepthShadowmap/CasterVP_HLSL +} +fragment_program Ogre/DepthShadowmap/CasterFP unified +{ + delegate Ogre/DepthShadowmap/CasterFP_GLSL + delegate Ogre/DepthShadowmap/CasterFP_GLSLES + delegate Ogre/DepthShadowmap/CasterFP_HLSL +} +vertex_program Ogre/DepthShadowmap/ReceiverVP unified +{ + delegate Ogre/DepthShadowmap/ReceiverVP_GLSL + delegate Ogre/DepthShadowmap/ReceiverVP_GLSLES + delegate Ogre/DepthShadowmap/ReceiverVP_HLSL +} +fragment_program Ogre/DepthShadowmap/ReceiverFP unified +{ + delegate Ogre/DepthShadowmap/ReceiverFP_GLSL + delegate Ogre/DepthShadowmap/ReceiverFP_GLSLES + delegate Ogre/DepthShadowmap/ReceiverFP_HLSL +} +fragment_program Ogre/DepthShadowmap/ReceiverFPPCF unified +{ + delegate Ogre/DepthShadowmap/ReceiverFPPCF_GLSL + delegate Ogre/DepthShadowmap/ReceiverFPPCF_GLSLES + delegate Ogre/DepthShadowmap/ReceiverFPPCF_HLSL +} +vertex_program Ogre/DepthShadowmap/NormalMapReceiverVP unified +{ + delegate Ogre/DepthShadowmap/NormalMapReceiverVP_GLSL + delegate Ogre/DepthShadowmap/NormalMapReceiverVP_GLSLES + delegate Ogre/DepthShadowmap/NormalMapReceiverVP_HLSL +} +fragment_program Ogre/DepthShadowmap/NormalMapReceiverFP unified +{ + delegate Ogre/DepthShadowmap/NormalMapReceiverFP_GLSL + delegate Ogre/DepthShadowmap/NormalMapReceiverFP_GLSLES + delegate Ogre/DepthShadowmap/NormalMapReceiverFP_HLSL +} +fragment_program Ogre/DepthShadowmap/NormalMapReceiverFPPCF unified +{ + delegate Ogre/DepthShadowmap/NormalMapReceiverFPPCF_GLSL + delegate Ogre/DepthShadowmap/NormalMapReceiverFPPCF_GLSLES + delegate Ogre/DepthShadowmap/NormalMapReceiverFPPCF_HLSL +} + +// **-- End Unified Section --** + + + +// Generic Shadow caster material (floating point shadowmap) +material Ogre/DepthShadowmap/Caster/Float +{ + technique + { + pass + { + vertex_program_ref Ogre/DepthShadowmap/CasterVP + { + } + fragment_program_ref Ogre/DepthShadowmap/CasterFP + { + } + } + } +} + +// Generic Shadow receiver material (floating point shadowmap) +material Ogre/DepthShadowmap/Receiver/Float +{ + technique + { + pass + { + vertex_program_ref Ogre/DepthShadowmap/ReceiverVP + { + } + fragment_program_ref Ogre/DepthShadowmap/ReceiverFP + { + } + texture_unit ShadowMap + { + tex_address_mode clamp + filtering none + } + } + } +} + + +// Specific receiver material for rockwall +material Ogre/DepthShadowmap/Receiver/RockWall +{ + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + // Base ambient pass + pass + { + // 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 + // Really basic vertex program + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + } + // Now do the lighting pass + // NB we don't do decal texture here because this is repeated per light + pass lighting + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + ambient 0 0 0 + + // do this for each light + iteration once_per_light + + + scene_blend add + + // Vertex program reference + vertex_program_ref Ogre/DepthShadowmap/ReceiverVP + { + } + shadow_receiver_vertex_program_ref Ogre/DepthShadowmap/ReceiverVP + { + } + + // Fragment program + fragment_program_ref Ogre/DepthShadowmap/ReceiverFP + { + } + shadow_receiver_fragment_program_ref Ogre/DepthShadowmap/ReceiverFP + { + } + + // shadowmap texture will be bound by code + + } + + // Decal pass + pass + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + lighting off + // Really basic vertex program + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + param_named ambient float4 1 1 1 1 + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + scene_blend dest_colour zero + + + texture_unit + { + texture rockwall.tga + } + + } + } + + +} + +// Specific receiver material for Athene +material Ogre/DepthShadowmap/Receiver/Athene +{ + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + // Base ambient pass + pass + { + // 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 + // Really basic vertex program + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + } + // Now do the lighting pass + // NB we don't do decal texture here because this is repeated per light + pass lighting + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + ambient 0 0 0 + + // do this for each light + iteration once_per_light + + + scene_blend add + + // Vertex program reference + vertex_program_ref Ogre/DepthShadowmap/NormalMapReceiverVP + { + } + shadow_receiver_vertex_program_ref Ogre/DepthShadowmap/NormalMapReceiverVP + { + } + + // Fragment program + fragment_program_ref Ogre/DepthShadowmap/NormalMapReceiverFP + { + } + shadow_receiver_fragment_program_ref Ogre/DepthShadowmap/NormalMapReceiverFP + { + } + + // shadowmap texture will be bound by code + + // Base bump map + texture_unit + { + texture atheneNormalMap.png + colour_op replace + } + // Normalisation cube map + texture_unit + { + cubic_texture nm.png combinedUVW + tex_coord_set 1 + tex_address_mode clamp + } + + } + + // Decal pass + pass + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + lighting off + // Really basic vertex program + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + param_named ambient float4 1 1 1 1 + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + scene_blend dest_colour zero + + texture_unit + { + texture egyptrockyfull.jpg + } + + } + } + + +} + + + +// Specialisation to use PCF +material Ogre/DepthShadowmap/Receiver/Float/PCF : Ogre/DepthShadowmap/Receiver/Float +{ + technique + { + pass + { + // override just receiver program + fragment_program_ref Ogre/DepthShadowmap/ReceiverFPPCF + { + } + + } + } +} + +// Specialisation to use PCF +material Ogre/DepthShadowmap/Receiver/RockWall/PCF : Ogre/DepthShadowmap/Receiver/RockWall +{ + technique + { + pass lighting + { + // override just receiver program + shadow_receiver_fragment_program_ref Ogre/DepthShadowmap/ReceiverFPPCF + { + } + + } + } +} +// Specialisation to use PCF +material Ogre/DepthShadowmap/Receiver/Athene/PCF : Ogre/DepthShadowmap/Receiver/Athene +{ + technique + { + pass lighting + { + // override just receiver program + shadow_receiver_fragment_program_ref Ogre/DepthShadowmap/NormalMapReceiverFPPCF + { + } + + } + } +} + + diff --git a/res/dist/media/materials/scripts/Dither.material b/res/dist/media/materials/scripts/Dither.material new file mode 100644 index 00000000000..67ff59e6172 --- /dev/null +++ b/res/dist/media/materials/scripts/Dither.material @@ -0,0 +1,57 @@ +fragment_program Ogre/Compositor/Dither_Cg_FP cg +{ + source DitherFP.cg + entry_point Dither_ps + profiles ps_4_0 ps_2_0 arbfp1 + +} + +fragment_program Ogre/Compositor/Dither_GLSLES_FP glsles +{ + source DitherFP.glsles +} + +fragment_program Ogre/Compositor/DitherFP unified +{ + delegate Ogre/Compositor/Dither_GLSLES_FP + delegate Ogre/Compositor/Dither_Cg_FP +} + +material Ogre/Compositor/Dither +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + + fragment_program_ref Ogre/Compositor/DitherFP + { + + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + texture_unit noise + { + texture DitherTex + tex_address_mode wrap + tex_coord_set 1 + filtering none + } + } + } +} \ No newline at end of file diff --git a/res/dist/media/materials/scripts/DualQuaternion.material b/res/dist/media/materials/scripts/DualQuaternion.material new file mode 100644 index 00000000000..97e45dd0fba --- /dev/null +++ b/res/dist/media/materials/scripts/DualQuaternion.material @@ -0,0 +1,112 @@ +material jaiquaDualQuatTest +{ + // Hardware skinning technique + technique + { + pass + { + vertex_program_ref Ogre/DualQuaternionHardwareSkinningTwoWeights + { + } + + shadow_caster_vertex_program_ref Ogre/DualQuaternionHardwareSkinningTwoWeightsShadowCaster + { + } + + texture_unit + { + texture blue_jaiqua.jpg + tex_address_mode clamp + } + } + } +} + +material spine +{ + // Hardware skinning technique - GLES2 passthrough fragment program + technique + { + pass + { + diffuse 1 1 1 + texture_unit + { + texture circuit.dds + } + + vertex_program_ref Ogre/HardwareSkinningTwoWeights + { + } + shadow_caster_vertex_program_ref Ogre/HardwareSkinningTwoWeightsShadowCaster + { + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } + } + } + + // Hardware skinning technique - no fragment program + technique + { + pass + { + diffuse 1 1 1 + texture_unit + { + texture circuit.dds + } + + vertex_program_ref Ogre/HardwareSkinningTwoWeights + { + + } + + // alternate shadow caster program + shadow_caster_vertex_program_ref Ogre/HardwareSkinningTwoWeightsShadowCaster + { + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } + } + } + + // Software blending technique + technique + { + pass + { + diffuse 1 1 1 + texture_unit + { + texture circuit.dds + } + } + } +} + +material spineDualQuat +{ + // Hardware skinning technique + technique + { + pass + { + diffuse 1 1 1 + texture_unit + { + texture circuit.dds + } + + vertex_program_ref Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhase + { + } + + shadow_caster_vertex_program_ref Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseShadowCaster + { + } + } + } +} diff --git a/res/dist/media/materials/scripts/DualQuaternion.program b/res/dist/media/materials/scripts/DualQuaternion.program new file mode 100644 index 00000000000..56835283f3d --- /dev/null +++ b/res/dist/media/materials/scripts/DualQuaternion.program @@ -0,0 +1,154 @@ +/////////////////////////////////////////////////////////////////////////// +/// Declare CG shaders for skinning +/////////////////////////////////////////////////////////////////////////// +// Dual quaternion hardware skinning using two indexed weights per vertex +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsCg cg +{ + source DualQuaternion.cg + entry_point dualQuaternionHardwareSkinningTwoWeights_vp + profiles vp40 vs_2_0 vs_1_1 arbvp1 + includes_skeletal_animation true + + default_params + { + param_named_auto diffuse surface_diffuse_colour + } +} + +// Dual quaternion two phase hardware skinning using two indexed weights per vertex, supports scaling and shearing +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseCg cg +{ + source DualQuaternion.cg + entry_point dualQuaternionHardwareSkinningTwoWeightsTwoPhase_vp + profiles vp40 vs_2_0 vs_1_1 arbvp1 + includes_skeletal_animation true + + default_params + { + param_named_auto diffuse surface_diffuse_colour + } +} + +/////////////////////////////////////////////////////////////////////////// +/// Declare CG shaders for shadow casters +/////////////////////////////////////////////////////////////////////////// +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsShadowCasterCg cg +{ + source DualQuaternion.cg + entry_point dualQuaternionHardwareSkinningTwoWeightsCaster_vp + profiles vp40 vs_2_0 vs_1_1 arbvp1 + includes_skeletal_animation true +} + +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseShadowCasterCg cg +{ + source DualQuaternion.cg + entry_point dualQuaternionHardwareSkinningTwoWeightsTwoPhaseCaster_vp + profiles vp40 vs_2_0 vs_1_1 arbvp1 + includes_skeletal_animation true +} + +/////////////////////////////////////////////////////////////////////////// +/// Declare GLSL shaders for skinning +/////////////////////////////////////////////////////////////////////////// +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsCommon glsl +{ + source DualQuaternion_Common.glsl +} + +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsGLSL glsl +{ + source DualQuaternion.glsl + attach Ogre/DualQuaternionHardwareSkinningTwoWeightsCommon + includes_skeletal_animation true +} + +// Dual quaternion two phase hardware skinning using two indexed weights per vertex, supports scaling and shearing +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseGLSL glsl +{ + source DualQuaternion_TwoPhase.glsl + attach Ogre/DualQuaternionHardwareSkinningTwoWeightsCommon + includes_skeletal_animation true +} + +/////////////////////////////////////////////////////////////////////////// +/// Declare GLSL shaders for shadow casters +/////////////////////////////////////////////////////////////////////////// +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsShadowCasterGLSL glsl +{ + source DualQuaternion_ShadowCaster.glsl + attach Ogre/DualQuaternionHardwareSkinningTwoWeightsCommon + includes_skeletal_animation true +} + +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseShadowCasterGLSL glsl +{ + source DualQuaternion_TwoPhaseShadowCaster.glsl + attach Ogre/DualQuaternionHardwareSkinningTwoWeightsCommon + includes_skeletal_animation true +} + +/////////////////////////////////////////////////////////////////////////// +/// Declare unified shaders +/////////////////////////////////////////////////////////////////////////// +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeights unified +{ + delegate Ogre/DualQuaternionHardwareSkinningTwoWeightsGLSL + delegate Ogre/DualQuaternionHardwareSkinningTwoWeightsCg + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto lightPos[0] light_position 0 + param_named_auto lightPos[1] light_position 1 + param_named_auto lightDiffuseColour[0] light_diffuse_colour 0 + param_named_auto lightDiffuseColour[1] light_diffuse_colour 1 + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsShadowCaster unified +{ + delegate Ogre/DualQuaternionHardwareSkinningTwoWeightsShadowCasterGLSL + delegate Ogre/DualQuaternionHardwareSkinningTwoWeightsShadowCasterCg + + 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/DualQuaternionHardwareSkinningTwoWeightsTwoPhase unified +{ + delegate Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseGLSL + delegate Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseCg + + 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 lightPos[0] light_position 0 + param_named_auto lightPos[1] light_position 1 + param_named_auto lightDiffuseColour[0] light_diffuse_colour 0 + param_named_auto lightDiffuseColour[1] light_diffuse_colour 1 + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseShadowCaster unified +{ + delegate Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseShadowCasterGLSL + delegate Ogre/DualQuaternionHardwareSkinningTwoWeightsTwoPhaseShadowCasterCg + + 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 + } +} diff --git a/res/dist/media/materials/scripts/Embossed.material b/res/dist/media/materials/scripts/Embossed.material new file mode 100644 index 00000000000..0ee6a9f2897 --- /dev/null +++ b/res/dist/media/materials/scripts/Embossed.material @@ -0,0 +1,44 @@ +fragment_program Ogre/Compositor/Embossed_Cg_FP cg +{ + source GrayScale.cg + entry_point Embossed_ps + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/Embossed_GLSLES_FP glsles +{ + source EmbossedFp.glsles +} + +fragment_program Ogre/Compositor/Embossed_FP unified +{ + delegate Ogre/Compositor/Embossed_GLSLES_FP + delegate Ogre/Compositor/Embossed_Cg_FP +} + +material Ogre/Compositor/Embossed +{ + technique + { + + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp + { + } + + fragment_program_ref Ogre/Compositor/Embossed_FP + { + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + } + } +} diff --git a/res/dist/media/materials/scripts/Example-Water.material b/res/dist/media/materials/scripts/Example-Water.material new file mode 100644 index 00000000000..431eec5dd41 --- /dev/null +++ b/res/dist/media/materials/scripts/Example-Water.material @@ -0,0 +1,183 @@ + +material Examples/Water0 +{ + technique + { + pass + { + scene_blend colour_blend + depth_write off + + texture_unit + { + texture Water01.jpg + env_map spherical + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water1 +{ + technique + { + pass + { + scene_blend colour_blend + depth_write off + + texture_unit + { + texture BeachStones.jpg + scale 0.25 0.25 + } + + texture_unit + { + texture Water01.jpg + env_map spherical + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water2 +{ + technique + { + pass + { + scene_blend colour_blend + depth_write off + + texture_unit + { + texture Water01.jpg + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water3 +{ + technique + { + pass + { + scene_blend colour_blend + depth_write off + + texture_unit + { + texture Water02.jpg + env_map spherical + scroll_anim 0.01 0.01 + rotate_anim 0.03 + } + } + } +} +material Examples/Water4 +{ + technique + { + pass + { + cull_hardware none + cull_software none + + texture_unit + { + texture Water02.jpg + env_map spherical + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water5 +{ + technique + { + pass + { + cull_hardware none + cull_software none + + texture_unit + { + texture BeachStones.jpg + scale 0.25 0.25 + } + + texture_unit + { + texture Water01.jpg + env_map spherical + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water6 +{ + technique + { + pass + { + lighting off + + texture_unit + { + cubic_texture cubescene.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} +material Examples/Water7 +{ + technique + { + pass + { + cull_hardware none + cull_software none + + texture_unit + { + texture BeachStones.jpg + scale 0.25 0.25 + } + + texture_unit + { + cubic_texture cubescene.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} +material Examples/Water8 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + cull_hardware none + cull_software none + + texture_unit + { + cubic_texture cubescene.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} diff --git a/res/dist/media/materials/scripts/Examples-Advanced.material b/res/dist/media/materials/scripts/Examples-Advanced.material new file mode 100644 index 00000000000..2faf2691f43 --- /dev/null +++ b/res/dist/media/materials/scripts/Examples-Advanced.material @@ -0,0 +1,842 @@ +// ------------------------------- +// Cel Shading Section +// ------------------------------- +vertex_program Ogre/CelShadingVPCg cg +{ + source Example_CelShading.cg + entry_point main_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + param_named shininess float 10 + } +} + +fragment_program Ogre/CelShadingFPCg cg +{ + source Example_CelShading.cg + entry_point main_fp + profiles ps_4_0 ps_1_1 arbfp1 fp20 + +} + +vertex_program Ogre/CelShadingVPGLSLES glsles +{ + source Example_CelShadingVp.glsles + profiles glsles + + default_params + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + param_named shininess float 10 + } +} + +fragment_program Ogre/CelShadingFPGLSLES glsles +{ + source Example_CelShadingFp.glsles + profiles glsles +} + +fragment_program Ogre/CelShadingFP unified +{ + delegate Ogre/CelShadingFPGLSLES + delegate Ogre/CelShadingFPCg +} + +vertex_program Ogre/CelShadingVP unified +{ + delegate Ogre/CelShadingVPGLSLES + delegate Ogre/CelShadingVPCg +} + +material Examples/CelShading +{ + technique + { + pass + { + vertex_program_ref Ogre/CelShadingVP + { + // map shininess from custom renderable param 1 + param_named_auto shininess custom 1 + } + fragment_program_ref Ogre/CelShadingFP + { + // map diffuse from custom renderable param 2 + param_named_auto diffuse custom 2 + // map specular from custom renderable param 3 + param_named_auto specular custom 3 + } + texture_unit + { + texture cel_shading_diffuse.png 1d + tex_address_mode clamp + filtering none + } + texture_unit + { + texture cel_shading_specular.png 1d + tex_address_mode clamp + filtering none + } + texture_unit + { + texture cel_shading_edge.png 1d + tex_address_mode clamp + filtering none + } + } + } + +} + + + +//------------------------ +// Bump mapping section +//------------------------ + +// Bump map vertex program, support for this is required +vertex_program Examples/BumpMapVPCg cg +{ + source Example_BumpMapping.cg + entry_point main_vp + profiles vs_4_0 vs_1_1 arbvp1 +} + +vertex_program Examples/BumpMapVPGLSLES glsles +{ + source Example_BumpMappingVp.glsles + profiles glsles +} + +vertex_program Examples/BumpMapVP unified +{ + delegate Examples/BumpMapVPGLSLES + delegate Examples/BumpMapVPCg +} + +// Bump map vertex program, with tangent parity support for this is required +vertex_program Examples/BumpMapVPTangentParity cg +{ + source Example_BumpMapping.cg + entry_point main_vp + profiles vs_1_1 arbvp1 + compile_arguments -DTANGENTS_HAVE_PARITY=1 +} + +// Bump map fragment program, support for this is optional +fragment_program Examples/BumpMapFPCg cg +{ + source Example_BumpMapping.cg + entry_point main_fp + profiles ps_4_0 ps_2_0 arbfp1 fp20 +} + +fragment_program Examples/BumpMapFPGLSLES glsles +{ + source Example_BumpMappingFp.glsles + profiles glsles + default_params + { + // assign samplers as required by GLSL + param_named normalMap int 0 + } +} + +fragment_program Examples/BumpMapFP unified +{ + delegate Examples/BumpMapFPGLSLES + delegate Examples/BumpMapFPCg +} + +// Bump map vertex program shadow receiver +vertex_program Examples/BumpMapVPShadowRcvCg cg +{ + source Example_BumpMapping.cg + entry_point main_shadowreceiver_vp + profiles vs_1_1 arbvp1 +} + +// Bump map vertex program shadow receiver +vertex_program Examples/BumpMapVPShadowRcvGLSLES glsles +{ + source Example_BumpMappingShadowRcvVp.glsles + profiles glsles +} + +vertex_program Examples/BumpMapVPShadowRcv unified +{ + delegate Examples/BumpMapVPShadowRcvGLSLES + delegate Examples/BumpMapVPShadowRcvCg +} + +// Bump map fragment program shadow receiver, support for this is optional +fragment_program Examples/BumpMapFPShadowRcvCg cg +{ + source Example_BumpMapping.cg + entry_point main_shadowreceiver_fp + profiles ps_2_0 arbfp1 fp20 +} + +// Bump map fragment program shadow receiver, support for this is optional +fragment_program Examples/BumpMapFPShadowRcvGLSLES glsles +{ + source Example_BumpMappingShadowRcvFp.glsles + profiles glsles + default_params + { + // assign samplers as required by GLSL + param_named shadowMap int 0 + param_named normalMap int 1 + } +} + +fragment_program Examples/BumpMapFPShadowRcv unified +{ + delegate Examples/BumpMapFPShadowRcvGLSLES + delegate Examples/BumpMapFPShadowRcvCg +} + +// Bump map with specular vertex program, support for this is required +vertex_program Examples/BumpMapVPSpecularCg cg +{ + source Example_BumpMapping.cg + entry_point specular_vp + profiles vs_4_0 vs_1_1 arbvp1 +} + +// Bump map with specular vertex program, support for this is required +vertex_program Examples/BumpMapVPSpecularGLSLES glsles +{ + source Example_BumpMappingSpecularVp.glsles + profiles glsles +} + +vertex_program Examples/BumpMapVPSpecular unified +{ + delegate Examples/BumpMapVPSpecularGLSLES + delegate Examples/BumpMapVPSpecularCg +} + +// Bump map fragment program, support for this is optional +fragment_program Examples/BumpMapFPSpecularCg cg +{ + source Example_BumpMapping.cg + entry_point specular_fp + profiles ps_4_0 ps_2_0 arbfp1 fp20 +} + +// Bump map fragment program, support for this is optional +fragment_program Examples/BumpMapFPSpecularGLSLES glsles +{ + source Example_BumpMappingSpecularFp.glsles + profiles glsles + default_params + { + // assign samplers as required by GLSL + param_named normalMap int 0 + } +} + +fragment_program Examples/BumpMapFPSpecular unified +{ + delegate Examples/BumpMapFPSpecularGLSLES + delegate Examples/BumpMapFPSpecularCg +} + +// Any number of lights, diffuse +material Examples/BumpMapping/MultiLight +{ + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + 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 + // Really basic vertex program + // NB we don't use fixed function here because GL does not like + // mixing fixed function and vertex programs, depth fighting can + // be an issue + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + param_named_auto ambient ambient_light_colour + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + + } + // Now do the lighting pass + // NB we don't do decal texture here because this is repeated per light + pass perlight + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + ambient 0 0 0 + + // do this for each light + iteration once_per_light + + + scene_blend add + + // Vertex program reference + vertex_program_ref Examples/BumpMapVP + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto worldViewProj worldviewproj_matrix + } + + // Fragment program + fragment_program_ref Examples/BumpMapFP + { + param_named_auto lightDiffuse light_diffuse_colour 0 + } + + // texture shadow receiver program + shadow_receiver_vertex_program_ref Examples/BumpMapVPShadowRcv + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto worldMatrix world_matrix + param_named_auto texViewProj texture_viewproj_matrix + } + // Additive texture shadow receiver program + shadow_receiver_fragment_program_ref Examples/BumpMapFPShadowRcv + { + param_named_auto lightDiffuse light_diffuse_colour 0 + } + + // Base bump map + texture_unit normalmap + { + texture NMBumpsOut.png + colour_op replace + } + } + + // Decal pass + pass decal + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + lighting off + // Really basic vertex program + // NB we don't use fixed function here because GL does not like + // mixing fixed function and vertex programs, depth fighting can + // be an issue + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + param_named ambient float4 1 1 1 1 + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + scene_blend dest_colour zero + texture_unit decalmap + { + texture RustedMetal.jpg + } + + } + } + + +} + +// Any number of lights, diffuse and specular +material Examples/BumpMapping/MultiLightSpecular : Examples/BumpMapping/MultiLight +{ + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + // Overlay nothing new onto the old ambient pass + pass ambient + { + } + // Now do the lighting pass + // NB we don't do decal texture here because this is repeated per light + pass perlight + { + + // Vertex program reference + vertex_program_ref Examples/BumpMapVPSpecular + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + } + + // Fragment program + fragment_program_ref Examples/BumpMapFPSpecular + { + param_named_auto lightDiffuse light_diffuse_colour 0 + param_named_auto lightSpecular light_specular_colour 0 + } + + } + + } + +} + +// Any number of lights, diffuse only, correct for tangent parity +material Examples/BumpMapping/MultiLightTangentParity : Examples/BumpMapping/MultiLight +{ + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + // Overlay nothing new onto the old ambient pass + pass ambient + { + } + // Now do the lighting pass + // NB we don't do decal texture here because this is repeated per light + pass perlight + { + + // Just change the vertex program + vertex_program_ref Examples/BumpMapVPTangentParity + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto worldViewProj worldviewproj_matrix + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + + } + + } + +} + + + +//--------------------------- +// Projective texture section +//--------------------------- + + +vertex_program Examples/TexProjectionVP cg +{ + source Example_Projection.cg + entry_point generalPurposeProjection_vp + profiles vs_1_1 arbvp1 +} + +fragment_program Examples/TexProjectionFP cg +{ + source Example_Projection.cg + entry_point generalPurposeProjection_fp + // sorry, ps_1_1 can't do this, fp20 can though + profiles ps_2_0 arbfp1 fp20 +} + +material Examples/GeneralTexProjection +{ + technique + { + pass + { + + vertex_program_ref Examples/TexProjectionVP + { + param_named_auto worldViewProjMatrix worldviewproj_matrix + param_named_auto worldMatrix world_matrix + // You'll need to update the tex projection, I suggest using + // the Frustum class + //param_named_auto texWorldViewProj worldviewproj_matrix + } + fragment_program_ref Examples/TexProjectionFP + { + // no params + } + texture_unit + { + // Project the OGRE logo + texture ogrelogo.png + tex_address_mode clamp + } + } + + + } + +} + +//---------------------------- +// Distortion effects +//---------------------------- + +vertex_program Examples/FresnelRefractReflectVPCg cg +{ + source Example_Fresnel.cg + entry_point main_vp + profiles vs_4_0 vs_1_1 arbvp1 +} +vertex_program Examples/FresnelRefractReflectVPold cg +{ + source Example_Fresnel.cg + entry_point main_vp_old + profiles vs_1_1 arbvp1 +} +vertex_program Examples/FresnelRefractReflectVPGLSLES glsles +{ + source Example_FresnelVp.glsles + entry_point main + profiles glsles +} + +vertex_program Examples/FresnelRefractReflectVP unified +{ + delegate Examples/FresnelRefractReflectVPGLSLES + delegate Examples/FresnelRefractReflectVPCg +} + +fragment_program Examples/FresnelRefractReflectFPCg cg +{ + source Example_Fresnel.cg + entry_point main_fp + // sorry, ps_1_1 and fp20 can't do this + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Examples/FresnelRefractReflectPS asm +{ + source Example_FresnelPS.asm + // sorry, only for ps_1_4 :) + syntax ps_1_4 +} + +fragment_program Examples/FresnelRefractReflectFPGLSLES glsles +{ + source Example_FresnelFp.glsles + entry_point main + profiles glsles + default_params + { + // assign samplers as required by GLSL + param_named noiseMap int 0 + param_named reflectMap int 1 + param_named refractMap int 2 + } +} + +fragment_program Examples/FresnelRefractReflectFP unified +{ + delegate Examples/FresnelRefractReflectFPGLSLES + delegate Examples/FresnelRefractReflectFPCg +} + +material Examples/FresnelReflectionRefraction +{ + // ps_2_0 / arbfp1 + technique + { + pass + { + + vertex_program_ref Examples/FresnelRefractReflectVP + { + param_named_auto worldViewProjMatrix worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + param_named_auto timeVal time 0.05 + param_named scroll float 1 + param_named scale float 1 + param_named noise float 1 + // scroll and noisePos will need updating per frame + } + fragment_program_ref Examples/FresnelRefractReflectFP + { + param_named fresnelBias float -0.1 + param_named fresnelScale float 1.8 + param_named fresnelPower float 8 + param_named tintColour float4 0 0.05 0.05 1 + param_named noiseScale float 0.05 + } + // Noise + texture_unit + { + // Perlin noise volume + texture waves2.dds + // min / mag filtering, no mip + filtering linear linear none + } + // Reflection + texture_unit + { + // Will be filled in at runtime + texture reflection + tex_address_mode clamp + } + // Refraction + texture_unit + { + // Will be filled in at runtime + texture refraction + tex_address_mode clamp + } + } + + + } + + // ATI 8500 + + technique + { + pass + { + vertex_program_ref Examples/FresnelRefractReflectVPold + { + param_named_auto worldViewProjMatrix worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + param_named fresnelBias float -0.3 + param_named fresnelScale float 1.4 + param_named fresnelPower float 8 + param_named_auto timeVal time_0_1 20 + param_named scroll float 1 + param_named scale float 4 + param_named noise float 1 + // scroll and noisePos will need updating per frame + } + + // for ATI RADEON 8500 - 9200 + fragment_program_ref Examples/FresnelRefractReflectPS + { + // distortionRange + param_indexed 0 float 0.025 + // tintColour + param_indexed 1 float4 0.05 0.12 0.15 1 + } + + // Noise + texture_unit + { + // Perlin noise volume + texture perlinvolume.dds 3d + // min / mag filtering, no mip + filtering linear linear none + } + // Reflection + texture_unit + { + // Will be filled in at runtime + texture Reflection + tex_address_mode clamp + } + // Refraction + texture_unit + { + // Will be filled in at runtime + texture Refraction + tex_address_mode clamp + } + } + } + +} + +// Normal-mapped Athene statue +material Examples/Athene/NormalMapped : Examples/BumpMapping/MultiLight +{ + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + // Now do the lighting pass + // NB we don't do decal texture here because this is repeated per light + pass perlight + { + + + // Base bump map + texture_unit normalmap + { + texture atheneNormalMap.png + colour_op replace + } + } + + // Decal pass + pass decal + { + texture_unit decalmap + { + texture egyptrockyfull.jpg + } + + } + } +} + +// Basic Athene statue +material Examples/Athene/Basic +{ + + technique + { + pass + { + ambient 0.3 0.3 0.3 + diffuse 1.0 1.0 0.9 + + texture_unit + { + texture egyptrockyfull.jpg + } + + } + } +} + + +// Any number of lights, diffuse and specular +material Examples/Athene/NormalMappedSpecular : Examples/BumpMapping/MultiLightSpecular +{ + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + // Now do the lighting pass + // NB we don't do decal texture here because this is repeated per light + pass perlight + { + + // Base bump map + texture_unit normalmap + { + texture atheneNormalMap.png + } + } + + // Decal pass + pass decal + { + texture_unit decalmap + { + texture egyptrockyfull.jpg + } + + } + + } +} + + +vertex_program Examples/TextureArrayVScg cg +{ + source Example_TextureArrayVS.cg + entry_point textureArray_v + profiles vs_4_0 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Examples/TextureArrayVSglsl glsl +{ + source Example_TextureArrayVS.glsl + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +fragment_program Examples/TextureArrayPSglsl glsl +{ + source Example_TextureArrayPS.glsl + + default_params + { + param_named TextureArrayTex int 0 + } +} + +fragment_program Examples/TextureArrayPShlsl4 hlsl +{ + entry_point textureArray_p + source Example_TextureArrayPS.hlsl4 + target ps_4_0 +} + +fragment_program Examples/TextureArrayPSasm asm +{ + source Example_TextureArrayPS.asm + syntax gp4fp +} + +material Examples/TextureArray +{ + technique + { + pass + { + fragment_program_ref Examples/TextureArrayPSasm + { + } + + } + } + + + technique HLSL4 + { + pass + { + vertex_program_ref Examples/TextureArrayVScg + { + } + + fragment_program_ref Examples/TextureArrayPShlsl4 + { + } + } + } + + technique GLSL + { + pass + { + vertex_program_ref Examples/TextureArrayVSglsl + { + } + + fragment_program_ref Examples/TextureArrayPSglsl + { + } + + texture_unit + { + // Will be filled in at runtime + texture TextureArrayTex + tex_address_mode clamp + } + } + } + +} diff --git a/res/dist/media/materials/scripts/Examples-DynTex.material b/res/dist/media/materials/scripts/Examples-DynTex.material new file mode 100644 index 00000000000..048a5a74939 --- /dev/null +++ b/res/dist/media/materials/scripts/Examples-DynTex.material @@ -0,0 +1,38 @@ +material Examples/Frost +{ + technique + { + pass + { + lighting off + depth_write off + scene_blend colour_blend + + texture_unit + { + texture frost.png + scale 0.5 0.5 + } + + texture_unit + { + texture thaw + } + } + } +} + +material Examples/VTDarkStuff +{ + technique + { + pass + { + diffuse 0.0 0.0 0.0 + ambient 0.1 0.1 0.15 + cull_hardware none + lighting off + } + + } +} diff --git a/res/dist/media/materials/scripts/Examples-Water.material b/res/dist/media/materials/scripts/Examples-Water.material new file mode 100644 index 00000000000..431eec5dd41 --- /dev/null +++ b/res/dist/media/materials/scripts/Examples-Water.material @@ -0,0 +1,183 @@ + +material Examples/Water0 +{ + technique + { + pass + { + scene_blend colour_blend + depth_write off + + texture_unit + { + texture Water01.jpg + env_map spherical + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water1 +{ + technique + { + pass + { + scene_blend colour_blend + depth_write off + + texture_unit + { + texture BeachStones.jpg + scale 0.25 0.25 + } + + texture_unit + { + texture Water01.jpg + env_map spherical + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water2 +{ + technique + { + pass + { + scene_blend colour_blend + depth_write off + + texture_unit + { + texture Water01.jpg + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water3 +{ + technique + { + pass + { + scene_blend colour_blend + depth_write off + + texture_unit + { + texture Water02.jpg + env_map spherical + scroll_anim 0.01 0.01 + rotate_anim 0.03 + } + } + } +} +material Examples/Water4 +{ + technique + { + pass + { + cull_hardware none + cull_software none + + texture_unit + { + texture Water02.jpg + env_map spherical + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water5 +{ + technique + { + pass + { + cull_hardware none + cull_software none + + texture_unit + { + texture BeachStones.jpg + scale 0.25 0.25 + } + + texture_unit + { + texture Water01.jpg + env_map spherical + scroll_anim 0.01 0.01 + } + } + } +} +material Examples/Water6 +{ + technique + { + pass + { + lighting off + + texture_unit + { + cubic_texture cubescene.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} +material Examples/Water7 +{ + technique + { + pass + { + cull_hardware none + cull_software none + + texture_unit + { + texture BeachStones.jpg + scale 0.25 0.25 + } + + texture_unit + { + cubic_texture cubescene.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} +material Examples/Water8 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + cull_hardware none + cull_software none + + texture_unit + { + cubic_texture cubescene.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} diff --git a/res/dist/media/materials/scripts/Examples.compositor b/res/dist/media/materials/scripts/Examples.compositor new file mode 100644 index 00000000000..45c2249e606 --- /dev/null +++ b/res/dist/media/materials/scripts/Examples.compositor @@ -0,0 +1,788 @@ +//Dark Sylinc's Bloom +compositor Bloom +{ + technique + { + // Temporary textures + texture rt_output target_width target_height PF_R8G8B8 + texture rt0 target_width_scaled 0.25 target_height_scaled 0.25 PF_R8G8B8 + texture rt1 target_width_scaled 0.25 target_height_scaled 0.25 PF_R8G8B8 + + target rt_output + { + // Render output from previous compositor (or original scene) + input previous + } + + target rt0 + { + // Start with clear texture + input none + // Horizontal blur pass + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/BrightPass2 + input 0 rt_output + } + } + + target rt1 + { + // Start with clear texture + input none + // Horizontal blur pass + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/BlurV + input 0 rt0 + } + } + + target rt0 + { + // Start with clear texture + input none + // Horizontal blur pass + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/BlurH + input 0 rt1 + } + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/BloomBlend2 + input 0 rt_output + input 1 rt0 + } + } + } +} + +compositor Glass +{ + technique + { + texture rt0 target_width target_height PF_R8G8B8 + + target rt0 { input previous } + + target_output + { + // Start with clear output + input none + + pass render_quad + { + material Ogre/Compositor/GlassPass + input 0 rt0 + } + } + } +} + +compositor "Old TV" +{ + technique + { + texture rt0 target_width target_height PF_R8G8B8 + + // render scene to a texture + target rt0 { input previous } + + target_output + { + // Start with clear output + input none + + pass render_quad + { + // convert the previous render target to a black and white image, add some noise, distort it, + // then render to scene aligned quad + material Ogre/Compositor/OldTV + input 0 rt0 + } + } + } +} + + +// Black and white effect +compositor B&W +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/BlackAndWhite + input 0 rt0 + } + } + } +} + +//compositor DOF // based on Blur but final pass does depth of field +//{ +// technique +// { +// // Temporary textures +// texture rt0 target_width target_height PF_A8R8G8B8 +// texture rt1 target_width target_height PF_A8R8G8B8 +// +// target rt1 +// { +// // Render output from previous compositor (or original scene) +// input previous +// } +// +// target rt0 +// { +// // Start with clear texture +// input none +// // Vertical blur pass +// pass render_quad +// { +// // Renders a fullscreen quad with a material +// material Ogre/Compositor/DOF_Blur0 +// input 0 rt1 +// } +// } +// +// target rt1 +// { +// // Start with clear texture +// input none +// // Horizontal blur pass +// pass render_quad +// { +// // Renders a fullscreen quad with a material +// material Ogre/Compositor/DOF_Blur1 +// input 0 rt0 +// } +// } +// +// target_output +// { +// // Start with clear output +// input none +// // Draw a fullscreen quad +// pass render_quad +// { +// // Renders a fullscreen quad with a material +// material Ogre/Compositor/DOF_Blend +// input 0 rt0 +// input 1 rt1 +// } +// } +// } +//} + +// Embossed (fake bump) effect +compositor Embossed +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/Embossed + input 0 rt0 + } + } + } +} + +// SharpenEdges +compositor "Sharpen Edges" +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/SharpenEdges + input 0 rt0 + } + } + } +} + +// Invert +compositor Invert +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/Invert + input 0 rt0 + } + } + } +} + +// Posterize +compositor Posterize +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/Posterize + input 0 rt0 + } + } + } +} + +// Laplace +compositor Laplace +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/Laplace + input 0 rt0 + } + } + } +} + +// Tiling +compositor Tiling +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/Tiling + input 0 rt0 + } + } + } +} + +// Old Movie +compositor "Old Movie" +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/OldMovie + input 0 rt0 + } + } + } +} + +// HDR +compositor HDR +{ + // floating point only for now + technique + { + compositor_logic HDR + + // Temporary textures + // Fullsize HDR render target, used as tone mapping source + texture rt_full target_width target_height PF_FLOAT16_RGB + // Targets used for luminance evaluation (3x3 downsample, point filtering) + texture rt_lum0 1 1 PF_FLOAT16_RGB + texture rt_lum1 4 4 PF_FLOAT16_RGB + texture rt_lum2 16 16 PF_FLOAT16_RGB + texture rt_lum3 64 64 PF_FLOAT16_RGB + texture rt_lum4 128 128 PF_FLOAT16_RGB + // Bright-pass filtered target (tone mapped) + texture rt_brightpass 128 128 PF_R8G8B8 + // Bloom filter targets + texture rt_bloom0 128 128 PF_R8G8B8 + texture rt_bloom1 128 128 PF_R8G8B8 + + + target rt_full + { + // No input, render differently + input none + + // Use float target HDR material scheme (unclamped shaders) + material_scheme HDR + + pass clear + { + } + + pass render_scene + { + } + + } + + // Downsample the original HDR scene to extract luminence value + target rt_lum4 + { + input none + pass render_quad + { + // Downsample using a 2x2 filter and convert to greyscale + material Ogre/Compositor/HDR/Downsample2x2Luminence + input 0 rt_full + identifier 994 + } + } + target rt_lum3 + { + input none + pass render_quad + { + // Downsample using a 3x3 filter + material Ogre/Compositor/HDR/Downsample3x3 + input 0 rt_lum4 + identifier 993 + } + } + target rt_lum2 + { + input none + pass render_quad + { + // Downsample using a 3x3 filter + material Ogre/Compositor/HDR/Downsample3x3 + input 0 rt_lum3 + identifier 992 + } + } + target rt_lum1 + { + input none + pass render_quad + { + // Downsample using a 3x3 filter + material Ogre/Compositor/HDR/Downsample3x3 + input 0 rt_lum2 + identifier 991 + } + } + target rt_lum0 + { + input none + pass render_quad + { + // Downsample using a 3x3 filter + material Ogre/Compositor/HDR/Downsample3x3 + input 0 rt_lum1 + identifier 990 + } + } + + + target rt_brightpass + { + input none + pass render_quad + { + // Downsample using a 3x3 filter, hi-pass and tone map + material Ogre/Compositor/HDR/Downsample3x3Brightpass + input 0 rt_full + input 1 rt_lum0 + identifier 800 + } + } + + target rt_bloom1 + { + input none + pass render_quad + { + // Blur horizontally + material Ogre/Compositor/HDR/GaussianBloom + input 0 rt_brightpass + identifier 701 + } + } + target rt_bloom0 + { + input none + pass render_quad + { + // Blur horizontally + material Ogre/Compositor/HDR/GaussianBloom + input 0 rt_bloom1 + identifier 700 + } + } + + + // Final output combines tone mapping of the original scene, with an + // exposure setting passed in as a GPU parameter, and an additive bloom + // effect + target_output + { + input none + pass render_quad + { + material Ogre/Compositor/HDR/ToneMapping + input 0 rt_full + input 1 rt_bloom0 + input 2 rt_lum0 + } + } + + + } + +} + + +// Gaussian blur effect +compositor "Gaussian Blur" +{ + technique + { + compositor_logic GaussianBlur + + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + texture rt1 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target rt1 + { + // Blur horizontally + input none + pass render_quad + { + material Ogre/Compositor/HDR/GaussianBloom + input 0 rt0 + identifier 700 + } + } + + target_output + { + // Start with clear output + input none + // Blur vertically + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/HDR/GaussianBloom + input 0 rt1 + identifier 701 + } + } + } +} + +// Testing MRT +compositor TestMRT +{ + technique + { + // temporary texture (MRT!) + // 4 sub-surfaces, all 32-bit + texture mrt0 target_width target_height PF_A8R8G8B8 PF_A8R8G8B8 PF_A8R8G8B8 PF_A8R8G8B8 + + target mrt0 + { + // Render scene using MRT-compatible material scheme + input none + material_scheme MRT + pass clear + { + + } + pass render_scene + { + } + } + + target_output + { + input none + pass render_quad + { + // Renders a fullscreen quad + material Ogre/MRTtest/quad + // bind 4 MRT surfaces as texture inputs + input 0 mrt0 0 + input 1 mrt0 1 + input 2 mrt0 2 + input 3 mrt0 3 + } + + } + + } +} + +//Radial blur effect +compositor "Radial Blur" +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Blur vertically + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/Radial_Blur + input 0 rt0 + } + } + } +} + +// ASCII effect +compositor ASCII +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/ASCII + input 0 rt0 + } + } + } +} + +// Halftone effect +compositor Halftone +{ + technique + { + // Temporary textures + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + // Render output from previous compositor (or original scene) + input previous + } + + target_output + { + // Start with clear output + input none + // Draw a fullscreen quad with the black and white image + pass render_quad + { + // Renders a fullscreen quad with a material + material Ogre/Compositor/Halftone + input 0 rt0 + } + } + } +} + +//Night Vision effect +compositor "Night Vision" +{ + technique + { + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + input previous + } + + target_output + { + input none + + pass render_quad + { + material Ogre/Compositor/NightVision + input 0 rt0 + } + } + } +} + +//Dither effect +compositor Dither +{ + technique + { + texture rt0 target_width target_height PF_A8R8G8B8 + + target rt0 + { + input previous + } + + target_output + { + input none + + pass render_quad + { + material Ogre/Compositor/Dither + input 0 rt0 + } + } + } +} + diff --git a/res/dist/media/materials/scripts/Examples.material b/res/dist/media/materials/scripts/Examples.material new file mode 100644 index 00000000000..5b3de8d1d67 --- /dev/null +++ b/res/dist/media/materials/scripts/Examples.material @@ -0,0 +1,2035 @@ +material Examples/SphereMappedRustySteel +{ + technique + { + pass + { + texture_unit + { + texture RustySteel.jpg + } + + texture_unit + { + texture spheremap.png + colour_op_ex add src_texture src_current + colour_op_multipass_fallback one one + env_map spherical + } + } + } +} + +material Examples/OgreLogo +{ + technique + { + pass + { + ambient 0.8 0.8 0.8 + + texture_unit + { + texture ogrelogo.png + } + } + } +} + +material Examples/BeachStones +{ + technique + { + pass + { + ambient 0.1 0.1 0.1 + + texture_unit + { + texture BeachStones.jpg + } + } + } +} + +material Examples/TrippySkyBox +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture nm.png separateUV + tex_address_mode clamp + } + } + } +} + +material Examples/SpaceSkyBox +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture stevecube.jpg separateUV + tex_address_mode clamp + } + } + } +} + +material Examples/SceneSkyBox1 +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture cubemap_fr.jpg cubemap_bk.jpg cubemap_lf.jpg cubemap_rt.jpg cubemap_up.jpg cubemap_dn.jpg separateUV + tex_address_mode clamp + } + } + } +} + +material Examples/SceneCubeMap1 +{ + technique + { + pass + { + lighting off + + texture_unit + { + cubic_texture cubemap.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} + +material Examples/SceneSkyBox2 +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture cubescene_fr.jpg cubescene_bk.jpg cubescene_lf.jpg cubescene_rt.jpg cubescene_up.jpg cubescene_dn.jpg separateUV + tex_address_mode clamp + } + } + } +} + +material Examples/SceneCubeMap2 +{ + technique + { + pass + { + lighting off + + texture_unit + { + cubic_texture cubescene.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} + +material Examples/CloudyNoonSkyBox +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture cloudy_noon.jpg separateUV + tex_address_mode clamp + } + } + } +} + +material Examples/StormySkyBox +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture stormy.jpg separateUV + tex_address_mode clamp + } + } + } +} + +material Examples/EarlyMorningSkyBox +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture early_morning.jpg separateUV + tex_address_mode clamp + } + } + } +} + +fragment_program Examples/MorningSkyBoxHDRfpGLSLES glsles +{ + source hdrFp.glsles + profiles glsles +} + +fragment_program Examples/MorningSkyBoxHDRfpCg cg +{ + source hdr.cg + entry_point morningskybox_fp + profiles ps_2_0 arbfp1 +} + +fragment_program Examples/MorningSkyBoxHDRfp unified +{ + delegate Examples/MorningSkyBoxHDRfpGLSLES + delegate Examples/MorningSkyBoxHDRfpCg +} + +material Examples/MorningSkyBox +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture morning.jpg separateUV + tex_address_mode clamp + } + } + } + + // HDR technique (fake) + technique + { + scheme HDR + + pass + { + lighting off + depth_write off + + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + param_named ambient float4 1 1 1 1 + } + fragment_program_ref Examples/MorningSkyBoxHDRfp + { + } + + texture_unit + { + cubic_texture morning.jpg separateUV + tex_address_mode clamp + } + } + } +} + +fragment_program Examples/MorningCubeMapHDRfp cg +{ + source hdr.cg + entry_point morningcubemap_fp + profiles ps_2_0 arbfp1 + +} + +material Examples/MorningCubeMap +{ + technique + { + pass + { + lighting off + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } + // HDR technique (fake) + technique + { + scheme HDR + + pass + { + lighting off + + fragment_program_ref Examples/MorningCubeMapHDRfp + { + } + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} + +material Examples/EveningSkyBox +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture evening.jpg separateUV + tex_address_mode clamp + } + } + } +} + +material Examples/DynamicCubeMap +{ + technique + { + pass + { + texture_unit + { + // will be filled in at runtime + cubic_texture dyncubemap combinedUVW + tex_address_mode clamp + env_map cubic_reflection + } + } + } +} + +material Examples/CloudySky +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + texture clouds.jpg + scroll_anim 0.15 0 + } + } + } +} + +material Examples/RustySteel +{ + technique + { + pass + { + texture_unit + { + texture RustySteel.jpg + } + } + } +} + +material Examples/Chrome +{ + technique + { + pass + { + texture_unit + { + texture Chrome.jpg + env_map spherical + } + } + } +} + +material Examples/SpaceSkyPlane +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + texture spacesky.jpg + } + } + } +} + +material Examples/OgreDance +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + cull_hardware none + cull_software none + + texture_unit + { + anim_texture ogredance.png 8 2 + filtering none + } + } + } +} + +material Examples/OgreParade : Examples/OgreDance +{ + technique + { + pass + { + texture_unit + { + scroll 0.5 0 + scale 0.5 0.5 + scroll_anim 0 0.5 + } + } + } +} + +material Examples/OgreSpin : Examples/OgreDance +{ + technique + { + pass + { + texture_unit + { + texture ogredance_1.png + rotate_anim 0.25 + tex_address_mode clamp + } + } + } +} + +material Examples/OgreWobble : Examples/OgreDance +{ + technique + { + pass + { + texture_unit + { + texture ogredance_6.png + wave_xform scale_x sine 1 1.2 0 0.35 + wave_xform scale_y sine 1 1 0.5 0.25 + tex_address_mode clamp + } + } + } +} + +material Examples/BumpyMetal +{ + technique + { + pass + { + ambient 0.75 0.75 0.75 + + texture_unit + { + texture BumpyMetal.jpg + } + } + } +} + +material Examples/WaterStream +{ + technique + { + pass + { + ambient 0.1 0.1 0.1 + scene_blend add + depth_write off + cull_software none + cull_hardware none + + texture_unit + { + texture Water01.jpg + scroll_anim 0.125 0 + } + + texture_unit + { + texture Water01.jpg + wave_xform scroll_y sine 0 0.1 0 0.25 + } + } + } +} + +material Examples/Flare +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + diffuse vertexcolour + + texture_unit + { + texture flare.png + } + } + } +} +material Examples/Flare2 +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + diffuse vertexcolour + + texture_unit + { + texture flaretrail.png + } + } + } +} +material Examples/Flare3 +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + diffuse vertexcolour + + texture_unit + { + texture flare_alpha.dds + } + } + } +} +material Examples/FlarePointSprite +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + diffuse vertexcolour + + point_sprites on + point_size 2 + point_size_attenuation on + + texture_unit + { + texture flare.png + } + } + } +} + +material Examples/Droplet +{ + technique + { + pass + { + emissive 0.3 0.3 0.3 + scene_blend colour_blend + depth_write off + diffuse vertexcolour + lighting off + + texture_unit + { + texture basic_droplet.png + } + } + } +} +material Examples/Hilite/Yellow +{ + technique + { + pass + { + + texture_unit + { + texture dkyellow.png + } + } + } +} +material Examples/Rocky +{ + technique + { + pass + { + ambient 0.2 0.2 0.2 + + texture_unit + { + texture egyptrockyfull.jpg + } + } + } +} +material Examples/10PointBlock +{ + technique + { + pass + { + + texture_unit + { + texture 10points.png + } + } + } +} +material Material__25 +{ + technique + { + pass + { + + texture_unit + { + texture texmap2.jpg + } + } + } +} +material "2 - Default" +{ + technique + { + pass + { + + texture_unit + { + texture MtlPlat2.jpg + } + } + } +} +material "Material #8" +{ + technique + { + pass + { + + texture_unit + { + texture BODY.jpg + } + } + } +} +material "Material #3" +{ + technique + { + pass + { + + texture_unit + { + texture HEAD4.jpg + } + } + } +} +material "Material #9" +{ + technique + { + pass + { + + texture_unit + { + texture LEGS.jpg + } + } + } +} + +material Examples/Fish +{ + technique + { + pass + { + texture_unit + { + texture steelhead.png + } + } + } +} +material Examples/Ninja +{ + technique + { + pass + { + + texture_unit + { + texture nskingr.jpg + } + } + } +} + +material Examples/Robot +{ + // Hardware skinning technique + technique + { + pass + { + vertex_program_ref Ogre/HardwareSkinningOneWeight + { + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto lightPos[0] light_position 0 + param_named_auto lightPos[1] light_position 1 + param_named_auto lightDiffuseColour[0] light_diffuse_colour 0 + param_named_auto lightDiffuseColour[1] light_diffuse_colour 1 + param_named_auto ambient ambient_light_colour + + } + // alternate shadow caster program + shadow_caster_vertex_program_ref Ogre/HardwareSkinningOneWeightShadowCaster + { + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } + + texture_unit + { + texture r2skin.jpg + } + } + } + + // Software blending technique + technique + { + pass + { + + texture_unit + { + texture r2skin.jpg + } + } + } +} + +material Examples/GrassFloor +{ + technique + { + pass + { + texture_unit + { + texture grass_1024.jpg + } + } + } +} + +vertex_program Examples/GrassWaverVpCg cg +{ + source Grass.cg + entry_point grass_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + + // param_named_auto camObjPos camera_position_object_space + + param_named_auto ambient ambient_light_colour + param_named_auto objSpaceLight light_position_object_space 0 + param_named_auto lightColour light_diffuse_colour 0 + + param_named_auto offset custom 999 + } +} + +vertex_program Examples/GrassWaverTexVpCg cg + { + source Grass.cg + entry_point grassTex_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto offset custom 999 + } +} +vertex_program Examples/GrassWaverAmbientVpCg cg +{ + source Grass.cg + entry_point grassAmbient_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto ambient ambient_light_colour + param_named_auto offset custom 999 + } +} +fragment_program Examples/GrassWaverAmbientFpCg cg +{ + source Grass.cg + entry_point grassAmbient_fp + profiles ps_4_0 ps_2_0 arbfp1 + default_params + { + } +} +fragment_program Examples/GrassWaverFpCg cg +{ + source Grass.cg + entry_point grass_fp + profiles ps_4_0 ps_2_0 arbfp1 + default_params + { + } +} + +vertex_program Examples/GrassWaverCasterVpCg cg +{ + source Grass.cg + entry_point grasscaster_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto offset custom 999 + param_named_auto texelOffsets texel_offsets + } +} +fragment_program Examples/GrassWaverCasterFpCg cg +{ + source Grass.cg + entry_point grasscaster_fp + profiles ps_4_0 ps_2_0 arbfp1 + default_params + { + } +} + +vertex_program Examples/GrassWaverReceiverVpCg cg +{ + source Grass.cg + entry_point grassreceiver_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto world world_matrix + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texViewProj texture_viewproj_matrix + + param_named_auto camObjPos camera_position_object_space + + param_named_auto objSpaceLight light_position_object_space 0 + param_named_auto lightColour light_diffuse_colour 0 + + param_named_auto offset custom 999 + } +} + + +fragment_program Examples/GrassWaverReceiverFpCg cg +{ + source Grass.cg + entry_point grassreceiver_fp + profiles ps_4_0 ps_2_0 arbfp1 + + default_params + { + //param_named inverseShadowmapSize float 0.0009765625 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + } +} + +vertex_program Examples/GrassWaverVpGLSLES glsles +{ + source GrassVp.glsles + profiles glsles + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto camObjPos camera_position_object_space + param_named_auto ambient ambient_light_colour + param_named_auto objSpaceLight light_position_object_space 0 + param_named_auto lightColour light_diffuse_colour 0 + + param_named_auto offset custom 999 + } + } + +vertex_program Examples/GrassWaverTexVpGLSLES glsles +{ + source GrassTexVp.glsles + profiles glsles + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto offset custom 999 + } +} +vertex_program Examples/GrassWaverAmbientVpGLSLES glsles +{ + source GrassAmbientVp.glsles + profiles glsles + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto ambient ambient_light_colour + param_named_auto offset custom 999 + } +} +fragment_program Examples/GrassWaverAmbientFpGLSLES glsles +{ + source GrassAmbientFp.glsles + profiles glsles + default_params + { + param_named diffuseMap int 0 + } +} + +vertex_program Examples/GrassWaverCasterVpGLSLES glsles +{ + source GrassCasterVp.glsles + profiles glsles + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto offset custom 999 + param_named_auto texelOffsets texel_offsets + } +} +fragment_program Examples/GrassWaverCasterFpGLSLES glsles +{ + source GrassCasterFp.glsles + profiles glsles + default_params + { + param_named diffuseMap int 0 + } +} + +vertex_program Examples/GrassWaverReceiverVpGLSLES glsles +{ + source GrassReceiverVp.glsles + profiles glsles + + default_params + { + param_named_auto world world_matrix + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto texViewProj texture_viewproj_matrix + + param_named_auto camObjPos camera_position_object_space + + param_named_auto objSpaceLight light_position_object_space 0 + param_named_auto lightColour light_diffuse_colour 0 + + param_named_auto offset custom 999 + } +} + + +fragment_program Examples/GrassWaverReceiverFpGLSLES glsles +{ + source GrassReceiverFp.glsles + profiles glsles + + default_params + { + param_named shadowMap int 0 + param_named diffuseMap int 1 + param_named fixedDepthBias float 0.0005 + param_named gradientClamp float 0.0098 + param_named gradientScaleBias float 0 + } +} + +fragment_program Examples/GrassWaverFpGLSLES glsles +{ + source GrassFp.glsles + profiles glsles + default_params + { + param_named diffuseMap int 0 + } +} + +vertex_program Examples/GrassWaverReceiverVp unified +{ + delegate Examples/GrassWaverReceiverVpGLSLES + delegate Examples/GrassWaverReceiverVpCg +} + +fragment_program Examples/GrassWaverReceiverFp unified +{ + delegate Examples/GrassWaverReceiverFpGLSLES + delegate Examples/GrassWaverReceiverFpCg +} + +vertex_program Examples/GrassWaverCasterVp unified +{ + delegate Examples/GrassWaverCasterVpGLSLES + delegate Examples/GrassWaverCasterVpCg +} + +fragment_program Examples/GrassWaverCasterFp unified +{ + delegate Examples/GrassWaverCasterFpGLSLES + delegate Examples/GrassWaverCasterFpCg +} + +vertex_program Examples/GrassWaverAmbientVp unified +{ + delegate Examples/GrassWaverAmbientVpGLSLES + delegate Examples/GrassWaverAmbientVpCg +} + +fragment_program Examples/GrassWaverAmbientFp unified +{ + delegate Examples/GrassWaverAmbientFpGLSLES + delegate Examples/GrassWaverAmbientFpCg +} + +vertex_program Examples/GrassWaverTexVp unified +{ + delegate Examples/GrassWaverTexVpGLSLES + delegate Examples/GrassWaverTexVpCg +} + +fragment_program Examples/GrassWaverFp unified +{ + delegate Examples/GrassWaverFpGLSLES + delegate Examples/GrassWaverFpCg +} + +vertex_program Examples/GrassWaverVp unified +{ + delegate Examples/GrassWaverVpGLSLES + delegate Examples/GrassWaverVpCg +} + +material Examples/GrassBladesShadowCaster +{ + // Vertex program waving grass + technique + { + pass + { + vertex_program_ref Examples/GrassWaverCasterVp + { + } + fragment_program_ref Examples/GrassWaverCasterFp + { + } + + alpha_rejection greater 150 + + scene_blend alpha_blend + + cull_hardware none + cull_software none + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + } + + } +} + +material Examples/GrassBladesShadowReceiver +{ + // Vertex program waving grass + technique + { + pass + { + scene_blend add + + alpha_rejection greater 150 + + cull_hardware none + cull_software none + + vertex_program_ref Examples/GrassWaverReceiverVp + { + } + fragment_program_ref Examples/GrassWaverReceiverFp + { + } + + texture_unit ShadowMap + { + tex_address_mode border + tex_border_colour 1.0 1.0 1.0 0.0 + content_type shadow + filtering linear linear none + tex_coord_set 0 + } + + texture_unit + { + tex_address_mode clamp + tex_coord_set 1 + texture gras_02.png + } + } + + } +} + +material Examples/GrassBladesAdditiveFloatTransparentBest +{ + + transparency_casts_shadows on + receive_shadows on + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + shadow_caster_material Examples/GrassBladesShadowCaster + shadow_receiver_material Examples/GrassBladesShadowReceiver + + // Base ambient pass + pass + { + // 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 + + alpha_rejection greater 150 + + scene_blend alpha_blend + + cull_hardware none + cull_software none + + // Really basic vertex program + vertex_program_ref Examples/GrassWaverAmbientVp + { + } + + fragment_program_ref Examples/GrassWaverAmbientFp + { + } + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + + } + pass lighting + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + ambient 0 0 0 + + // do this for each light + iteration once_per_light + + + scene_blend add + + + vertex_program_ref Examples/GrassWaverAmbientVp + { + } + + fragment_program_ref Examples/GrassWaverAmbientFp + { + } + + + alpha_rejection greater 150 + + cull_hardware none + cull_software none + + texture_unit ShadowMap + { + tex_address_mode border + tex_border_colour 1.0 1.0 1.0 0.0 + content_type shadow + filtering linear linear none + tex_coord_set 0 + } + + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + } + // Decal pass + pass + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + lighting off + + alpha_rejection greater 150 + + //scene_blend alpha_blend + scene_blend dest_colour zero + + cull_hardware none + cull_software none + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + + vertex_program_ref Examples/GrassWaverVp + { + } + + + } + } +} + +material Examples/GrassBladesAdditiveFloatTransparent +{ + + transparency_casts_shadows on + receive_shadows on + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + shadow_caster_material Examples/GrassBladesShadowCaster + shadow_receiver_material Examples/GrassBladesShadowReceiver + + // Base ambient pass + pass + { + // 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 + + alpha_rejection greater 150 + + scene_blend alpha_blend + + cull_hardware none + cull_software none + + // Really basic vertex program + vertex_program_ref Examples/GrassWaverAmbientVp + { + } + + fragment_program_ref Examples/GrassWaverAmbientFp + { + } + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + + } + pass lighting + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + ambient 0 0 0 + + // do this for each light + iteration once_per_light + + + scene_blend add + + + vertex_program_ref Examples/GrassWaverAmbientVp + { + } + + fragment_program_ref Examples/GrassWaverAmbientFp + { + } + + + alpha_rejection greater 150 + + cull_hardware none + cull_software none + + texture_unit ShadowMap + { + tex_address_mode border + tex_border_colour 1.0 1.0 1.0 0.0 + content_type shadow + filtering linear linear none + tex_coord_set 0 + } + + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + } + // Decal pass + pass + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + lighting off + + alpha_rejection greater 150 + + //scene_blend alpha_blend + scene_blend dest_colour zero + + cull_hardware none + cull_software none + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + + vertex_program_ref Examples/GrassWaverTexVp + { + } + + + } + } +} + +material Examples/GrassBladesAdditiveFloat +{ + transparency_casts_shadows on + receive_shadows on + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + shadow_caster_material Ogre/DepthShadowmap/Caster/Float + shadow_receiver_material Ogre/DepthShadowmap/Receiver/Float + + // Base ambient pass + pass + { + // 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 + // Really basic vertex program + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + + } + pass lighting + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + ambient 0 0 0 + + // do this for each light + iteration once_per_light + + + scene_blend add + + + vertex_program_ref Examples/GrassWaverAmbientVp + { + } + + fragment_program_ref Examples/GrassWaverAmbientFp + { + } + + + alpha_rejection greater 150 + scene_blend alpha_blend + + cull_hardware none + cull_software none + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + } + // Decal pass + pass + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + lighting off + + alpha_rejection greater 150 + scene_blend alpha_blend + + cull_hardware none + cull_software none + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + + vertex_program_ref Examples/GrassWaverAmbientVp + { + } + + fragment_program_ref Examples/GrassWaverAmbientFp + { + } + + } + } + +} + +material Examples/GrassBladesAdditive +{ + transparency_casts_shadows on + receive_shadows on + // Vertex program waving grass + technique + { + pass + { + vertex_program_ref Examples/GrassWaverAmbientVp + { + } + + alpha_rejection greater 150 + scene_blend alpha_blend + + cull_hardware none + cull_software none + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + } + } +} + +material Examples/GrassBlades +{ + transparency_casts_shadows on + receive_shadows on + // Vertex program waving grass + technique + { + pass + { + vertex_program_ref Examples/GrassWaverVp + { + } + fragment_program_ref Examples/GrassWaverFp + { + } + + alpha_rejection greater 150 + scene_blend alpha_blend + + cull_hardware none + cull_software none + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + } + } + // fallback + technique + { + pass + { + alpha_rejection greater 150 + scene_blend alpha_blend + + cull_hardware none + cull_software none + + texture_unit + { + tex_address_mode clamp + texture gras_02.png + } + } + } +} + + +material Examples/Rockwall +{ + technique + { + pass + { + texture_unit + { + texture rockwall.tga + } + } + } +} + +material Examples/Aureola +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + diffuse vertexcolour + cull_hardware none + + texture_unit + { + texture aureola.png PF_BYTE_LA + tex_address_mode clamp + } + } + } +} + +// Test hardware morph animation (no normals) +material Examples/HardwareMorphAnimation +{ + technique + { + pass + { + + vertex_program_ref Ogre/HardwareMorphAnimation + { + // all default + } + + texture_unit + { + colour_op_ex source1 src_current src_current + } + + } + } +} + +// Test hardware pose animation (no normals) +material Examples/HardwarePoseAnimation +{ + technique + { + pass + { + + vertex_program_ref Ogre/HardwarePoseAnimation + { + // all default + } + texture_unit + { + tex_coord_set 0 + colour_op_ex source1 src_current src_current + } + + } + } +} + + +// Test hardware morph animation (with normals) +material Examples/HardwareMorphAnimationWithNormals +{ + technique + { + pass + { + + vertex_program_ref Ogre/HardwareMorphAnimationWithNormals + { + // all default + } + + texture_unit + { + colour_op_ex source1 src_current src_current + } + + } + } +} + +// Test hardware pose animation (no normals) +material Examples/HardwarePoseAnimationWithNormals +{ + technique + { + pass + { + + vertex_program_ref Ogre/HardwarePoseAnimationWithNormals + { + // all default + } + texture_unit + { + tex_coord_set 0 + colour_op_ex source1 src_current src_current + } + + } + } +} + +material RustyBarrel +{ + technique + { + pass + { + ambient 0.5 0.5 0.5 1.0 + diffuse 1.0 1.0 1.0 1.0 + specular 0.0 0.0 0.0 1.0 12.5 + emissive 0.0 0.0 0.0 1.0 + texture_unit + { + texture RustyBarrel.png + filtering trilinear + } + } + } +} + +material WoodPallet +{ + receive_shadows on + technique + { + pass + { + ambient 0.5 0.5 0.5 1.0 + diffuse 1.0 1.0 1.0 1.0 + specular 0.0 0.0 0.0 1.0 12.5 + + texture_unit + { + texture WoodPallet.png + filtering trilinear + } + } + } +} + +material Examples/LightRibbonTrail +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + diffuse vertexcolour + + texture_unit + { + texture ribbonband.png 1d + tex_address_mode clamp + filtering none + } + } + } +} + +material Examples/TudorHouse +{ + technique + { + pass + { + texture_unit + { + texture fw12b.jpg + tex_address_mode clamp + } + } + } +} + +material jaiqua +{ + // Hardware skinning technique - no fragment program + technique + { + pass + { + vertex_program_ref Ogre/HardwareSkinningTwoWeights + { + + } + + fragment_program_ref Ogre/BasicFragmentPrograms/DiffuseOneTexture + { + + } + + // alternate shadow caster program + shadow_caster_vertex_program_ref Ogre/HardwareSkinningTwoWeightsShadowCaster + { + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } + + texture_unit + { + texture blue_jaiqua.jpg + tex_address_mode clamp + } + } + } + // Software blending technique + technique + { + pass + { + texture_unit + { + texture blue_jaiqua.jpg + tex_address_mode clamp + } + } + } + +} + + +material Examples/Plane/IntegratedShadows +{ + technique + { + pass + { + // Single-pass shadowing + texture_unit + { + texture MtlPlat2.jpg + } + texture_unit + { + // standard modulation blend + content_type shadow + tex_address_mode clamp + } + } + } + +} + + +fragment_program Examples/ShowUV_pCg cg +{ + source Example_Basic.cg + entry_point showuv_p + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Examples/ShowUV_pGLSLES glsles +{ + source ShowUV.glsles + profiles glsles +} + +fragment_program Examples/ShowUV_p unified +{ + delegate Examples/ShowUV_pGLSLES + delegate Examples/ShowUV_pCg +} + +fragment_program Examples/ShowUVdir3D_pCg cg +{ + source Example_Basic.cg + entry_point showuvdir3d_p + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Examples/ShowUVdir3D_pGLSLES glsles +{ + source ShowUVdir3D.glsles + profiles glsles +} + +fragment_program Examples/ShowUVdir3D_p unified +{ + delegate Examples/ShowUVdir3D_pGLSLES + delegate Examples/ShowUVdir3D_pCg +} + +vertex_program Examples/ShowTangents_vCg cg +{ + source Example_Basic.cg + entry_point basicPassthroughTangent_v + profiles vs_2_0 arbvp1 + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Examples/ShowTangents_vGLSLES glsles +{ + source ShowTangents.glsles + profiles glsles + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Examples/ShowTangents_v unified +{ + delegate Examples/ShowTangents_vGLSLES + delegate Examples/ShowTangents_vCg +} + +vertex_program Examples/ShowNormals_vCg cg +{ + source Example_Basic.cg + entry_point basicPassthroughNormal_v + profiles vs_2_0 arbvp1 + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Examples/ShowNormals_vGLSLES glsles +{ + source ShowNormals.glsles + profiles glsles + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Examples/ShowNormals_v unified +{ + delegate Examples/ShowNormals_vGLSLES + delegate Examples/ShowNormals_vCg +} + +material Examples/ShowUV +{ + technique + { + pass + { + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureWithUV + { + param_named_auto worldViewProj worldviewproj_matrix + } + fragment_program_ref Examples/ShowUV_p + { + } + } + } + + technique + { + pass + { + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + } + fragment_program_ref Examples/ShowUV_p + { + } + } + } +} +material Examples/ShowTangents +{ + technique + { + pass + { + vertex_program_ref Examples/ShowTangents_v + { + } + fragment_program_ref Examples/ShowUVdir3D_p + { + } + } + } +} +material Examples/ShowNormals +{ + technique + { + pass + { + vertex_program_ref Examples/ShowNormals_v + { + } + fragment_program_ref Examples/ShowUVdir3D_p + { + } + } + } +} + + diff --git a/res/dist/media/materials/scripts/Examples.program b/res/dist/media/materials/scripts/Examples.program new file mode 100644 index 00000000000..b2cc2b20e37 --- /dev/null +++ b/res/dist/media/materials/scripts/Examples.program @@ -0,0 +1,340 @@ +//--------------------------------------------------- +// This file includes a number of basic GPU programs +// for use in many materials. +//--------------------------------------------------- + + +// A really basic ambient pass program, support for one texture coordinate set +vertex_program Ogre/BasicVertexPrograms/AmbientOneTextureCg cg +{ + source Example_Basic.cg + entry_point ambientOneTexture_vp + profiles vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto ambient ambient_light_colour + } + +} + +vertex_program Ogre/BasicVertexPrograms/AmbientOneTextureCgSm4 cg +{ + source Example_Basic.cg + entry_point ambientOneTexture_vp + profiles vs_4_0 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto ambient ambient_light_colour + } + +} + +// A really basic ambient pass program, support for one texture coordinate set +vertex_program Ogre/BasicVertexPrograms/AmbientOneTextureHLSL hlsl +{ + source Example_Basic.hlsl + entry_point ambientOneTexture_vp + target vs_4_0 vs_1_1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto ambient ambient_light_colour + } +} +// A really basic ambient pass program, support for one texture coordinate set +vertex_program Ogre/BasicVertexPrograms/AmbientOneTextureGLSL glsl +{ + source AmbientOneTexture.glsl + + default_params + { + param_named_auto ambient ambient_light_colour + } +} + +// A really basic ambient pass program, support for one texture coordinate set +vertex_program Ogre/BasicVertexPrograms/AmbientOneTextureGLSLES glsles +{ + source AmbientOneTexture.glsles + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/BasicVertexPrograms/AmbientOneTextureWithUV glsles +{ + source AmbientOneTextureWithUV.glsles + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/BasicVertexPrograms/AmbientOneTextureUnified unified +{ + delegate Ogre/BasicVertexPrograms/AmbientOneTextureGLSL + delegate Ogre/BasicVertexPrograms/AmbientOneTextureGLSLES + delegate Ogre/BasicVertexPrograms/AmbientOneTextureHLSL + delegate Ogre/BasicVertexPrograms/AmbientOneTextureCg + delegate Ogre/BasicVertexPrograms/AmbientOneTextureCgSm4 +} + +fragment_program Ogre/BasicFragmentPrograms/DiffuseOneTextureCg cg +{ + source Example_Basic.cg + entry_point diffuseOneTexture_fp + profiles ps_2_0 arbfp1 +} + +fragment_program Ogre/BasicFragmentPrograms/DiffuseOneTextureGLSLES glsles +{ + source DiffuseOneTexture.glsles + default_params + { + param_named texMap int 0 + } +} + +fragment_program Ogre/BasicFragmentPrograms/DiffuseOneTexture unified +{ + delegate Ogre/BasicFragmentPrograms/DiffuseOneTextureGLSLES + delegate Ogre/BasicFragmentPrograms/DiffuseOneTextureCg +} + +// A really basic ambient pass program, support for one texture coordinate set +fragment_program Ogre/BasicFragmentPrograms/PassthroughFP unified +{ + delegate Ogre/BasicFragmentPrograms/PassthroughFpGLSLES + delegate Ogre/BasicFragmentPrograms/PassthroughFpCgSm4 + delegate Ogre/BasicFragmentPrograms/PassthroughFpCg +} + +// A really basic ambient pass program, support for one texture coordinate set +fragment_program Ogre/BasicFragmentPrograms/PassthroughFpCgSm4 cg +{ + entry_point main + source PassthroughFP.cg + profiles ps_4_0 +} + +fragment_program Ogre/BasicFragmentPrograms/PassthroughFpCg cg +{ + entry_point mainCg + source PassthroughFP.cg + profiles ps_4_0 ps_2_0 arbfp1 +} + +// A really basic ambient pass program, support for one texture coordinate set +fragment_program Ogre/BasicFragmentPrograms/PassthroughFpCgSm4ForAmbientOneTexture cg +{ + entry_point mainForAmbientOneTexture + source PassthroughFP.cg + profiles ps_4_0 +} + + +// A really basic ambient pass program, support for one texture coordinate set +fragment_program Ogre/BasicFragmentPrograms/PassthroughFpGLSLES glsles +{ + source PassthroughFP.glsles +} + +// Same as below, but for use when rendering texture shadows +vertex_program Ogre/HardwareSkinningOneWeightShadowCaster cg +{ + source Example_Basic.cg + entry_point hardwareSkinningOneWeightCaster_vp + profiles vs_1_1 arbvp1 + includes_skeletal_animation true +} +// Basic hardware skinning using one indexed weight per vertex +vertex_program Ogre/HardwareSkinningOneWeight cg +{ + source Example_Basic.cg + entry_point hardwareSkinningOneWeight_vp + profiles vs_1_1 arbvp1 + includes_skeletal_animation true +} +// Same as below, but for use when rendering texture shadows +vertex_program Ogre/HardwareSkinningTwoWeightsShadowCasterCg cg +{ + source Example_Basic.cg + entry_point hardwareSkinningTwoWeightsCaster_vp + profiles vs_4_0 vs_1_1 arbvp1 + includes_skeletal_animation true +} + +// Same as below, but for use when rendering texture shadows +vertex_program Ogre/HardwareSkinningTwoWeightsShadowCasterHLSL hlsl +{ + source Example_Basic.hlsl + entry_point hardwareSkinningTwoWeightsCaster_vp + target vs_1_1 + includes_skeletal_animation true + column_major_matrices false +} + +vertex_program Ogre/HardwareSkinningTwoWeightsShadowCasterGLSL glsl +{ + source skinningTwoWeightsShadowCasterVp.glsl + includes_skeletal_animation true +} + +vertex_program Ogre/HardwareSkinningTwoWeightsShadowCasterGLSLES glsles +{ + source skinningTwoWeightsShadowCasterVp.glsles + includes_skeletal_animation true + use_optimiser false +} + +vertex_program Ogre/HardwareSkinningTwoWeightsShadowCaster unified +{ + delegate Ogre/HardwareSkinningTwoWeightsShadowCasterGLSLES + delegate Ogre/HardwareSkinningTwoWeightsShadowCasterHLSL + delegate Ogre/HardwareSkinningTwoWeightsShadowCasterGLSL + delegate Ogre/HardwareSkinningTwoWeightsShadowCasterCg +} + +// Basic hardware skinning using two indexed weights per vertex +vertex_program Ogre/HardwareSkinningTwoWeightsHLSL hlsl +{ + source Example_Basic.hlsl + entry_point hardwareSkinningTwoWeights_vp + target vs_1_1 + includes_skeletal_animation true + column_major_matrices false +} + +vertex_program Ogre/HardwareSkinningTwoWeightsGLSL glsl +{ + source skinningTwoWeightsVp.glsl + includes_skeletal_animation true +} + +vertex_program Ogre/HardwareSkinningTwoWeightsGLSLES glsles +{ + source skinningTwoWeightsVp.glsles + includes_skeletal_animation true + use_optimiser false +} + +vertex_program Ogre/HardwareSkinningTwoWeightsCg cg +{ + source Example_Basic.cg + entry_point hardwareSkinningTwoWeights_vp + profiles vs_4_0 vs_1_1 arbvp1 + includes_skeletal_animation true +} + +vertex_program Ogre/HardwareSkinningTwoWeights unified +{ + delegate Ogre/HardwareSkinningTwoWeightsGLSL + delegate Ogre/HardwareSkinningTwoWeightsGLSLES + delegate Ogre/HardwareSkinningTwoWeightsHLSL + delegate Ogre/HardwareSkinningTwoWeightsCg + + default_params + { + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto lightPos[0] light_position 0 + param_named_auto lightPos[1] light_position 1 + param_named_auto lightDiffuseColour[0] light_diffuse_colour 0 + param_named_auto lightDiffuseColour[1] light_diffuse_colour 1 + param_named_auto ambient ambient_light_colour + //This property isn't relevant for GLSL, uses the GLSL material state instead + param_named_auto diffuse surface_diffuse_colour + } +} + +// Basic hardware skinning using four indexed weights per vertex +vertex_program Ogre/HardwareSkinningFourWeights cg +{ + source Example_Basic.cg + entry_point hardwareSkinningFourWeights_vp + profiles vs_1_1 arbvp1 + includes_skeletal_animation true + + default_params + { + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto lightPos[0] light_position 0 + param_named_auto lightPos[1] light_position 1 + param_named_auto lightDiffuseColour[0] light_diffuse_colour 0 + param_named_auto lightDiffuseColour[1] light_diffuse_colour 1 + param_named_auto ambient ambient_light_colour + } +} + +// Basic hardware morph animation (no normals) +vertex_program Ogre/HardwareMorphAnimation cg +{ + source Example_Basic.cg + entry_point hardwareMorphAnimation + profiles vs_1_1 arbvp1 + + includes_morph_animation true + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto anim_t animation_parametric + } +} +// Basic hardware pose animation supporting 2 active poses (no normals) +vertex_program Ogre/HardwarePoseAnimation cg +{ + source Example_Basic.cg + entry_point hardwarePoseAnimation + profiles vs_1_1 arbvp1 + + includes_pose_animation 2 + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto anim_t animation_parametric + } +} + +// Basic hardware morph animation (with normals) +vertex_program Ogre/HardwareMorphAnimationWithNormals cg +{ + source Example_Basic.cg + entry_point hardwareMorphAnimationWithNormals + profiles vs_1_1 arbvp1 + + includes_morph_animation true + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto anim_t animation_parametric + param_named_auto objSpaceLightPos light_position_object_space 0 + param_named_auto ambient ambient_light_colour + } +} +// Basic hardware pose animation supporting 2 active poses (with normals) +vertex_program Ogre/HardwarePoseAnimationWithNormals cg +{ + source Example_Basic.cg + entry_point hardwarePoseAnimationWithNormals + profiles vs_1_1 arbvp1 + + includes_pose_animation 2 + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto anim_t animation_parametric + param_named_auto objSpaceLightPos light_position_object_space 0 + param_named_auto ambient ambient_light_colour + } +} diff --git a/res/dist/media/materials/scripts/GLSLSwizzle.material b/res/dist/media/materials/scripts/GLSLSwizzle.material new file mode 100644 index 00000000000..52b270c86df --- /dev/null +++ b/res/dist/media/materials/scripts/GLSLSwizzle.material @@ -0,0 +1,37 @@ +vertex_program Ogre/GPTest/Passthrough_VP_GLSL glsl +{ + source PassthroughVP.glsl +} + +geometry_program Ogre/GPTest/Swizzle_GP_GLSL glsl +{ + source SwizzleGP.glsl + input_operation_type triangle_list + output_operation_type line_strip + max_output_vertices 6 + + default_params + { + param_named origColor float4 1 0 0 1 + param_named cloneColor float4 1 1 1 0.3 + } +} + +material Ogre/GPTest/SwizzleGLSL +{ + technique + { + pass + { + vertex_program_ref Ogre/GPTest/Passthrough_VP_GLSL + { + + } + + geometry_program_ref Ogre/GPTest/Swizzle_GP_GLSL + { + + } + } + } +} diff --git a/res/dist/media/materials/scripts/Glass.material b/res/dist/media/materials/scripts/Glass.material new file mode 100644 index 00000000000..e48b09d4db3 --- /dev/null +++ b/res/dist/media/materials/scripts/Glass.material @@ -0,0 +1,56 @@ +fragment_program Ogre/Compositor/GlassFP_cg cg +{ + source GlassFP.cg + entry_point main_ps + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/GlassFP_glsles glsles +{ + source GlassFP.glsles + default_params + { + param_named RT int 0 + param_named NormalMap int 1 + } +} + +fragment_program Ogre/Compositor/GlassFP unified +{ + delegate Ogre/Compositor/GlassFP_glsles + delegate Ogre/Compositor/GlassFP_cg +} + +material Ogre/Compositor/GlassPass +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp + { + } + + fragment_program_ref Ogre/Compositor/GlassFP + { + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + + texture_unit + { + texture WaterNormal1.tga 2d + tex_coord_set 1 + //tex_address_mode clamp + filtering linear linear linear + } + } + } +} diff --git a/res/dist/media/materials/scripts/HWInstancing.material b/res/dist/media/materials/scripts/HWInstancing.material new file mode 100644 index 00000000000..f249883010c --- /dev/null +++ b/res/dist/media/materials/scripts/HWInstancing.material @@ -0,0 +1,131 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//-------------------------------------------------------------- +// GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HWBasic_glsl_vs glsl +{ + source HWBasicInstancing.vert + + preprocessor_defines DEPTH_SHADOWRECEIVER=1 +} + +vertex_program Ogre/Instancing/HWBasic/shadow_caster_glsl_vs glsl +{ + source HWBasicInstancing.vert + + preprocessor_defines DEPTH_SHADOWCASTER=1 +} + +//-------------------------------------------------------------- +// CG Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HWBasic_cg_vs cg +{ + source HWBasicInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER +} + +vertex_program Ogre/Instancing/HWBasic/shadow_caster_cg_vs cg +{ + source HWBasicInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER +} + +//-------------------------------------------------------------- +// Unified CG/GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HWBasic_vs unified +{ + delegate Ogre/Instancing/HWBasic_glsl_vs + delegate Ogre/Instancing/HWBasic_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/HWBasic/shadow_caster_vs unified +{ + delegate Ogre/Instancing/HWBasic/shadow_caster_glsl_vs + delegate Ogre/Instancing/HWBasic/shadow_caster_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +material Examples/Instancing/HWBasic/shadow_caster +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/HWBasic/shadow_caster_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + } + } +} + +abstract material Examples/Instancing/HWBasic +{ + technique + { + shadow_caster_material Examples/Instancing/HWBasic/shadow_caster + + pass + { + diffuse 0.3 0.3 0.3 + specular 0.1 0.1 0.1 0.1 12.5 + vertex_program_ref Ogre/Instancing/HWBasic_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + tex_address_mode clamp + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + } + } +} + +material Examples/Instancing/HWBasic/Robot : Examples/Instancing/HWBasic +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +material Examples/Instancing/HWBasic/spine : Examples/Instancing/HWBasic +{ + set_texture_alias DiffuseMap circuit.dds +} diff --git a/res/dist/media/materials/scripts/HW_VTFInstancing.material b/res/dist/media/materials/scripts/HW_VTFInstancing.material new file mode 100644 index 00000000000..ef6462a383d --- /dev/null +++ b/res/dist/media/materials/scripts/HW_VTFInstancing.material @@ -0,0 +1,445 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//-------------------------------------------------------------- +// GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HW_VTF_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines DEPTH_SHADOWRECEIVER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines DEPTH_SHADOWCASTER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + +vertex_program Ogre/Instancing/HW_VTF_dq_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,DEPTH_SHADOWRECEIVER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_dq_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,DEPTH_SHADOWCASTER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + +vertex_program Ogre/Instancing/HW_VTF_dq_two_weights_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,BONE_TWO_WEIGHTS,DEPTH_SHADOWRECEIVER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_dq_two_weights_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,BONE_TWO_WEIGHTS,DEPTH_SHADOWCASTER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + + +//-------------------------------------------------------------- +// CG Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HW_VTF_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/HW_VTF_dq_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DST_DUAL_QUATERNION + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_dq_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DST_DUAL_QUATERNION + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/HW_VTF_dq_two_weights_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DST_DUAL_QUATERNION -DBONE_TWO_WEIGHTS + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_dq_two_weights_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DST_DUAL_QUATERNION -DBONE_TWO_WEIGHTS + + uses_vertex_texture_fetch true +} + +//-------------------------------------------------------------- +// Unified CG/GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HW_VTF_vs unified +{ + delegate Ogre/Instancing/HW_VTF_glsl_vs + delegate Ogre/Instancing/HW_VTF_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_vs unified +{ + delegate Ogre/Instancing/VTF/HW/shadow_caster_glsl_vs + delegate Ogre/Instancing/VTF/HW/shadow_caster_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +vertex_program Ogre/Instancing/HW_VTF_dq_vs unified +{ + delegate Ogre/Instancing/HW_VTF_dq_glsl_vs + delegate Ogre/Instancing/HW_VTF_dq_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_dq_vs unified +{ + delegate Ogre/Instancing/VTF/HW/shadow_caster_dq_glsl_vs + delegate Ogre/Instancing/VTF/HW/shadow_caster_dq_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +vertex_program Ogre/Instancing/HW_VTF_dq_two_weights_vs unified +{ + delegate Ogre/Instancing/HW_VTF_dq_two_weights_glsl_vs + delegate Ogre/Instancing/HW_VTF_dq_two_weights_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/HW/shadow_caster_dq_two_weights_vs unified +{ + delegate Ogre/Instancing/VTF/HW/shadow_caster_dq_two_weights_glsl_vs + delegate Ogre/Instancing/VTF/HW/shadow_caster_dq_two_weights_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +material Examples/Instancing/VTF/HW/shadow_caster +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/HW/shadow_caster_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/shadow_caster_dq +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/HW/shadow_caster_dq_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/shadow_caster_dq_two_weights +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/HW/shadow_caster_dq_two_weights_vs + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +abstract material Examples/Instancing/HW_VTF +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/HW/shadow_caster + + pass + { + specular 1 1 1 1 12.5 + vertex_program_ref Ogre/Instancing/HW_VTF_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/Robot : Examples/Instancing/HW_VTF +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +abstract material Examples/Instancing/HW_VTF_dq +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/HW/shadow_caster_dq + + pass + { + specular 1 1 1 1 12.5 + + vertex_program_ref Ogre/Instancing/HW_VTF_dq_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/Robot_dq : Examples/Instancing/HW_VTF_dq +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +abstract material Examples/Instancing/HW_VTF_dq_two_weights +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/HW/shadow_caster_dq_two_weights + + pass + { + diffuse 0.3 0.3 0.3 + specular 0.1 0.1 0.1 0.1 12.5 + + vertex_program_ref Ogre/Instancing/HW_VTF_dq_two_weights_vs + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange shadow_scene_depth_range 0 + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + tex_address_mode clamp + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/spine_dq_two_weights : Examples/Instancing/HW_VTF_dq_two_weights +{ + set_texture_alias DiffuseMap circuit.dds +} diff --git a/res/dist/media/materials/scripts/HW_VTF_LUTInstancing.material b/res/dist/media/materials/scripts/HW_VTF_LUTInstancing.material new file mode 100644 index 00000000000..56de7243787 --- /dev/null +++ b/res/dist/media/materials/scripts/HW_VTF_LUTInstancing.material @@ -0,0 +1,438 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//-------------------------------------------------------------- +// GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HW_VTF_LUT_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines DEPTH_SHADOWRECEIVER=1,BONE_MATRIX_LUT=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines DEPTH_SHADOWCASTER=1,BONE_MATRIX_LUT=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + +vertex_program Ogre/Instancing/HW_VTF_LUT_dq_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,DEPTH_SHADOWRECEIVER=1,BONE_MATRIX_LUT=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,DEPTH_SHADOWCASTER=1,BONE_MATRIX_LUT=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + +vertex_program Ogre/Instancing/HW_VTF_LUT_dq_two_weights_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,BONE_TWO_WEIGHTS,DEPTH_SHADOWRECEIVER=1,BONE_MATRIX_LUT=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_two_weights_glsl_vs glsl +{ + source HW_VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,BONE_TWO_WEIGHTS,DEPTH_SHADOWCASTER=1,BONE_MATRIX_LUT=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + +//-------------------------------------------------------------- +// CG Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HW_VTF_LUT_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DBONE_MATRIX_LUT + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DBONE_MATRIX_LUT + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/HW_VTF_LUT_dq_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DBONE_MATRIX_LUT -DST_DUAL_QUATERNION + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DBONE_MATRIX_LUT -DST_DUAL_QUATERNION + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/HW_VTF_LUT_dq_two_weights_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DBONE_MATRIX_LUT -DST_DUAL_QUATERNION -DBONE_TWO_WEIGHTS + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_two_weights_cg_vs cg +{ + source HW_VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DBONE_MATRIX_LUT -DST_DUAL_QUATERNION -DBONE_TWO_WEIGHTS + + uses_vertex_texture_fetch true +} + +//-------------------------------------------------------------- +// Unified CG/GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/HW_VTF_LUT_vs unified +{ + delegate Ogre/Instancing/HW_VTF_LUT_glsl_vs + delegate Ogre/Instancing/HW_VTF_LUT_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_vs unified +{ + delegate Ogre/Instancing/VTF/HW/LUT/shadow_caster_glsl_vs + delegate Ogre/Instancing/VTF/HW/LUT/shadow_caster_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +vertex_program Ogre/Instancing/HW_VTF_LUT_dq_vs unified +{ + delegate Ogre/Instancing/HW_VTF_LUT_dq_glsl_vs + delegate Ogre/Instancing/HW_VTF_LUT_dq_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_vs unified +{ + delegate Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_glsl_vs + delegate Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +vertex_program Ogre/Instancing/HW_VTF_LUT_dq_two_weights_vs unified +{ + delegate Ogre/Instancing/HW_VTF_LUT_dq_two_weights_glsl_vs + delegate Ogre/Instancing/HW_VTF_LUT_dq_two_weights_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_two_weights_vs unified +{ + delegate Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_two_weights_glsl_vs + delegate Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_two_weights_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +material Examples/Instancing/VTF/HW/LUT/shadow_caster +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/HW/LUT/shadow_caster_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/LUT/shadow_caster_dq +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/LUT/shadow_caster_dq_two_weights +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/HW/LUT/shadow_caster_dq_two_weights_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +abstract material Examples/Instancing/HW_VTF_LUT +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/HW/LUT/shadow_caster + + pass + { + specular 1 1 1 1 12.5 + vertex_program_ref Ogre/Instancing/HW_VTF_LUT_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/LUT/Robot : Examples/Instancing/HW_VTF_LUT +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +abstract material Examples/Instancing/HW_VTF_LUT_dq +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/HW/LUT/shadow_caster_dq + + pass + { + specular 1 1 1 1 12.5 + vertex_program_ref Ogre/Instancing/HW_VTF_LUT_dq_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/LUT/Robot_dq : Examples/Instancing/HW_VTF_LUT_dq +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +abstract material Examples/Instancing/HW_VTF_LUT_dq_two_weights +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/HW/LUT/shadow_caster_dq_two_weights + + pass + { + diffuse 0.3 0.3 0.3 + specular 0.1 0.1 0.1 0.1 12.5 + vertex_program_ref Ogre/Instancing/HW_VTF_LUT_dq_two_weights_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + tex_address_mode clamp + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/HW/LUT/spine_dq_two_weights : Examples/Instancing/HW_VTF_LUT_dq_two_weights +{ + set_texture_alias DiffuseMap circuit.dds +} diff --git a/res/dist/media/materials/scripts/Halftone.material b/res/dist/media/materials/scripts/Halftone.material new file mode 100644 index 00000000000..91247a41c8e --- /dev/null +++ b/res/dist/media/materials/scripts/Halftone.material @@ -0,0 +1,56 @@ +fragment_program Ogre/Compositor/HalftoneFP cg +{ + source HalftoneFP.cg + entry_point Halftone_ps + profiles ps_4_0 ps_2_0 arbfp1 + + default_params + { + param_named numTiles float2 133.3 100 + param_named iNumTiles float2 0.00750750 0.01 + param_named iNumTiles2 float2 0.00375375 0.005 + param_named lum float4 0.30 0.59 0.11 0.0 + } +} + +material Ogre/Compositor/Halftone +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + + fragment_program_ref Ogre/Compositor/HalftoneFP + { + + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + texture_unit noise + { + texture HalftoneVolume + tex_coord_set 0 + filtering trilinear + tex_address_mode clamp + tex_border_colour 1.0 0.0 0.0 + } + + } + } +} + diff --git a/res/dist/media/materials/scripts/HeatVision.material b/res/dist/media/materials/scripts/HeatVision.material new file mode 100644 index 00000000000..c9914899a19 --- /dev/null +++ b/res/dist/media/materials/scripts/HeatVision.material @@ -0,0 +1,317 @@ +/////////////////////////////////// +// PASS 0 +// HEAT CASTERS PASS +/////////////////////////////////// + +vertex_program Fury/HeatVision/HeatCaster_Cg_vp cg +{ + source HeatVision.cg + entry_point HeatCaster_vp + profiles vs_1_1 arbvp1 +} + +fragment_program Fury/HeatVision/HeatCaster_Cg_fp cg +{ + source HeatVision.cg + entry_point HeatCaster_fp + profiles ps_2_0 arbfp1 +} + +vertex_program Fury/HeatVision/HeatCaster_GLSLES_vp glsles +{ + source HeatCasterVp.glsles +} + +fragment_program Fury/HeatVision/HeatCaster_GLSLES_fp glsles +{ + source HeatCasterFp.glsles +} + +vertex_program Fury/HeatVision/HeatCaster_vp unified +{ + delegate Fury/HeatVision/HeatCaster_GLSLES_vp + delegate Fury/HeatVision/HeatCaster_Cg_vp +} + +fragment_program Fury/HeatVision/HeatCaster_fp unified +{ + delegate Fury/HeatVision/HeatCaster_GLSLES_fp + delegate Fury/HeatVision/HeatCaster_Cg_fp +} + +material Fury/HeatVision/HeatCaster +{ + technique + { + pass + { + vertex_program_ref Fury/HeatVision/HeatCaster_vp + { + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + } + + fragment_program_ref Fury/HeatVision/HeatCaster_fp + { + } + } + } +} + +/////////////////////////////////// +// PASS 0 +// HEAT CASTERS PASS +/////////////////////////////////// + +vertex_program Fury/HeatVision/ColdCaster_Cg_vp cg +{ + source HeatVision.cg + entry_point ColdCaster_vp + profiles vs_1_1 arbvp1 +} + +fragment_program Fury/HeatVision/ColdCaster_Cg_fp cg +{ + source HeatVision.cg + entry_point ColdCaster_fp + profiles ps_2_0 arbfp1 +} + +vertex_program Fury/HeatVision/ColdCaster_GLSLES_vp glsles +{ + source ColdCasterVp.glsles +} + +fragment_program Fury/HeatVision/ColdCaster_GLSLES_fp glsles +{ + source ColdCasterFp.glsles +} + +vertex_program Fury/HeatVision/ColdCaster_vp unified +{ + delegate Fury/HeatVision/ColdCaster_GLSLES_vp + delegate Fury/HeatVision/ColdCaster_Cg_vp +} + +fragment_program Fury/HeatVision/ColdCaster_fp unified +{ + delegate Fury/HeatVision/ColdCaster_GLSLES_fp + delegate Fury/HeatVision/ColdCaster_Cg_fp +} + +material Fury/HeatVision/ColdCaster +{ + technique + { + pass + { + vertex_program_ref Fury/HeatVision/ColdCaster_vp + { + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + } + + fragment_program_ref Fury/HeatVision/ColdCaster_fp + { + } + } + } +} + +/////////////////////////////////// +// PASS 1 +// LIGHT TO HEAT CONVERSION PASS +/////////////////////////////////// + +vertex_program Fury/HeatVision/LightToHeat_Cg_vp cg +{ + source HeatVision.cg + entry_point LightToHeat_vp + profiles vs_1_1 arbvp1 + + default_params + { + param_named_auto flipping render_target_flipping + } +} + +fragment_program Fury/HeatVision/LightToHeat_Cg_fp cg +{ + source HeatVision.cg + entry_point LightToHeat_fp + profiles ps_2_0 arbfp1 +} + +vertex_program Fury/HeatVision/LightToHeat_GLSLES_vp glsles +{ + source LightToHeatVp.glsles + + default_params + { + param_named_auto flipping render_target_flipping + } +} + +fragment_program Fury/HeatVision/LightToHeat_GLSLES_fp glsles +{ + source LightToHeatFp.glsles + default_params + { + param_named Input int 0 + param_named NoiseMap int 1 + param_named HeatLookup int 2 + } +} + +vertex_program Fury/HeatVision/LightToHeat_vp unified +{ + delegate Fury/HeatVision/LightToHeat_GLSLES_vp + delegate Fury/HeatVision/LightToHeat_Cg_vp +} + +fragment_program Fury/HeatVision/LightToHeat_fp unified +{ + delegate Fury/HeatVision/LightToHeat_GLSLES_fp + delegate Fury/HeatVision/LightToHeat_Cg_fp +} + +material Fury/HeatVision/LightToHeat +{ + technique + { + // pass 1 + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Fury/HeatVision/LightToHeat_vp + { + } + + fragment_program_ref Fury/HeatVision/LightToHeat_fp + { + // these should be *really* random! + param_named random_fractions float4 0.3 0.7 0 0 + + param_named depth_modulator float4 0.6 0 0 0 + + // this one can be fixed + param_named heatBiasScale float4 0.0 1.0 0 0 + } + + // INPUT (from scene, where entities has "Fury/HeatVision/Caster" material for heat emanation) + texture_unit + { + tex_coord_set 0 + filtering linear linear none + tex_address_mode clamp + } + + // Noise map + texture_unit + { + texture HeatNoise.tga + tex_coord_set 0 + } + + // heat conversion texture + texture_unit + { + texture HeatLookup.tga + tex_coord_set 0 + filtering point point none + } + } + } + +} + + +/////////////////////////////////// +// PASS 2 +// BLUR PASS +/////////////////////////////////// + +vertex_program Fury/HeatVision/Blur_Cg_vp cg +{ + source HeatVision.cg + entry_point Blur_vp + profiles vs_1_1 arbvp1 + + default_params + { + param_named_auto flipping render_target_flipping + } +} + +fragment_program Fury/HeatVision/Blur_Cg_fp cg +{ + source HeatVision.cg + entry_point Blur_fp + profiles ps_2_0 arbfp1 +} + +vertex_program Fury/HeatVision/Blur_GLSLES_vp glsles +{ + source HeatBlurVp.glsles + + default_params + { + param_named_auto flipping render_target_flipping + } +} + +fragment_program Fury/HeatVision/Blur_GLSLES_fp glsles +{ + source HeatBlurFp.glsles + default_params + { + param_named Input int 0 + } +} + +vertex_program Fury/HeatVision/Blur_vp unified +{ + delegate Fury/HeatVision/Blur_GLSLES_vp + delegate Fury/HeatVision/Blur_Cg_vp +} + +fragment_program Fury/HeatVision/Blur_fp unified +{ + delegate Fury/HeatVision/Blur_GLSLES_fp + delegate Fury/HeatVision/Blur_Cg_fp +} + +material Fury/HeatVision/Blur +{ + technique + { + // pass 1 + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Fury/HeatVision/Blur_vp + { + } + + fragment_program_ref Fury/HeatVision/Blur_fp + { + param_named blurAmount float4 0.5 0 0 0 + } + + // INPUT (from previous) + texture_unit + { + texture Input + tex_coord_set 0 + filtering linear linear none + tex_address_mode clamp + } + } + } +} diff --git a/res/dist/media/materials/scripts/Hurt.material b/res/dist/media/materials/scripts/Hurt.material new file mode 100644 index 00000000000..e70ab4de693 --- /dev/null +++ b/res/dist/media/materials/scripts/Hurt.material @@ -0,0 +1,18 @@ +/// Just a simple red quad blended over the scene +material RedQuad +{ + technique + { + pass + { + lighting on + diffuse 0.0 0.0 0.0 0.5 + specular 0.0 0.0 0.0 1.0 + ambient 0.0 0.0 0.0 + emissive 1.0 0.0 0.0 + cull_hardware none + depth_check off + scene_blend alpha_blend + } + } +} diff --git a/res/dist/media/materials/scripts/InstancingMisc.material b/res/dist/media/materials/scripts/InstancingMisc.material new file mode 100644 index 00000000000..075464047a4 --- /dev/null +++ b/res/dist/media/materials/scripts/InstancingMisc.material @@ -0,0 +1,81 @@ +//--------------------------------------------------------------------------- +//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) + +//-------------------------------------------------------------- +// GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/Misc_glsl_vs glsl +{ + source InstancingMisc.vert + + preprocessor_defines DEPTH_SHADOWRECEIVER=1 +} + +//-------------------------------------------------------------- +// CG Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/Misc_cg_vs cg +{ + source InstancingMisc.cg + entry_point main_vs + profiles vs_3_0 vs_2_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER +} + +//-------------------------------------------------------------- +// Unified CG/GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/Misc_vs unified +{ + delegate Ogre/Instancing/Misc_glsl_vs + delegate Ogre/Instancing/Misc_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto worldMatrix world_matrix + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +abstract material Examples/Instancing/Misc +{ + technique + { + pass + { + specular 1 1 1 1 50 + vertex_program_ref Ogre/Instancing/Misc_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + } + } +} + +material Examples/Instancing/Misc/Grass : Examples/Instancing/Misc +{ + set_texture_alias DiffuseMap grass_1024.jpg +} diff --git a/res/dist/media/materials/scripts/Invert.material b/res/dist/media/materials/scripts/Invert.material new file mode 100644 index 00000000000..3cd57ba5006 --- /dev/null +++ b/res/dist/media/materials/scripts/Invert.material @@ -0,0 +1,47 @@ +fragment_program Ogre/Compositor/Invert_Cg_FP cg +{ + source InvertFP.cg + entry_point Invert_ps + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/Invert_GLSLES_FP glsles +{ + source InvertFP.glsles +} + +fragment_program Ogre/Compositor/InvertFP unified +{ + delegate Ogre/Compositor/Invert_GLSLES_FP + delegate Ogre/Compositor/Invert_Cg_FP +} + +material Ogre/Compositor/Invert +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + fragment_program_ref Ogre/Compositor/InvertFP + { + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + } + } +} diff --git a/res/dist/media/materials/scripts/IsoSurf.material b/res/dist/media/materials/scripts/IsoSurf.material new file mode 100644 index 00000000000..580a50360b7 --- /dev/null +++ b/res/dist/media/materials/scripts/IsoSurf.material @@ -0,0 +1,127 @@ +////////// +// HLSL // +////////// +vertex_program Ogre/IsoSurf/SampleFieldVS_HLSL hlsl +{ + source isosurf.hlsl + entry_point mainVS + target vs_4_0 + + default_params + { + param_named IsoValue float 1.0 + param_named_auto WorldViewProj worldviewproj_matrix + param_named_auto origWorldViewIT inverse_transpose_worldview_matrix + } +} + +geometry_program Ogre/IsoSurf/TessellateTetrahedraGS_HLSL hlsl +{ + source isosurf.hlsl + entry_point mainGS + target gs_4_0 + uses_adjacency_information true + + default_params + { + param_named IsoValue float 1 + } +} + +fragment_program Ogre/IsoSurf/MetaballPS_HLSL hlsl +{ + source isosurf.hlsl + entry_point mainPS + target ps_4_0 +} + +////////// +// CG // +////////// +vertex_program Ogre/IsoSurf/SampleFieldVS_CG cg +{ + source isosurf.cg + entry_point mainVS + profiles vp40 arbvp1 + + default_params + { + param_named IsoValue float 1.0 + param_named_auto WorldViewProj worldviewproj_matrix + param_named_auto origWorldViewIT inverse_transpose_worldview_matrix + } +} + +geometry_program Ogre/IsoSurf/TessellateTetrahedraGS_CG cg +{ + source isosurf.cg + entry_point mainGS + profiles gpu_gp gp4_gp + uses_adjacency_information true + + default_params + { + param_named IsoValue float 1 + } +} + +fragment_program Ogre/IsoSurf/MetaballPS_CG cg +{ + source isosurf.cg + entry_point mainPS + profiles fp40 arbfp1 +} + +vertex_program Ogre/IsoSurf/SampleFieldVS unified +{ + delegate Ogre/IsoSurf/SampleFieldVS_HLSL + delegate Ogre/IsoSurf/SampleFieldVS_CG + default_params + { + + } +} + +geometry_program Ogre/IsoSurf/TessellateTetrahedraGS unified +{ + delegate Ogre/IsoSurf/TessellateTetrahedraGS_HLSL + delegate Ogre/IsoSurf/TessellateTetrahedraGS_CG + default_params + { + + } +} + +fragment_program Ogre/IsoSurf/MetaballPS unified +{ + delegate Ogre/IsoSurf/MetaballPS_HLSL + delegate Ogre/IsoSurf/MetaballPS_CG + default_params + { + + } +} + +material Ogre/IsoSurf/TessellateTetrahedra +{ + technique + { + pass + { + vertex_program_ref Ogre/IsoSurf/SampleFieldVS + { + + } + + geometry_program_ref Ogre/IsoSurf/TessellateTetrahedraGS + { + + } + + fragment_program_ref Ogre/IsoSurf/MetaballPS + { + + } + } + } +} diff --git a/res/dist/media/materials/scripts/Laplace.material b/res/dist/media/materials/scripts/Laplace.material new file mode 100644 index 00000000000..fedeebf8255 --- /dev/null +++ b/res/dist/media/materials/scripts/Laplace.material @@ -0,0 +1,49 @@ +fragment_program Ogre/Compositor/Laplace_Cg_FP cg +{ + source LaplaceFP.cg + entry_point Laplace_ps + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/Laplace_GLSLES_FP glsles +{ + source LaplaceFP.glsles +} + +fragment_program Ogre/Compositor/LaplaceFP unified +{ + delegate Ogre/Compositor/Laplace_GLSLES_FP + delegate Ogre/Compositor/Laplace_Cg_FP +} + +material Ogre/Compositor/Laplace +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + fragment_program_ref Ogre/Compositor/LaplaceFP + { + param_named pixelSize float 0.0031 + param_named scale float 1.0 + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + } + } +} diff --git a/res/dist/media/materials/scripts/MRTtest.material b/res/dist/media/materials/scripts/MRTtest.material new file mode 100644 index 00000000000..fa5fe7cefb2 --- /dev/null +++ b/res/dist/media/materials/scripts/MRTtest.material @@ -0,0 +1,133 @@ +// Scene material +// MRT testing +fragment_program Ogre/MRTtest/scenefp/HLSL hlsl +{ + source mrttestfp.hlsl + entry_point mainfp_scene + target ps_2_0 +} + +fragment_program Ogre/MRTtest/scenefp/GLSL glsl +{ + source mrttestfp_scene.glsl +} + +fragment_program Ogre/MRTtest/scenefp/GLSLES glsles +{ + source mrttestfp_scene.glsles +} + +fragment_program Ogre/MRTtest/scenefp unified +{ + delegate Ogre/MRTtest/scenefp/HLSL + delegate Ogre/MRTtest/scenefp/GLSL + delegate Ogre/MRTtest/scenefp/GLSLES +} + +material Ogre/MRTtest/scene +{ + technique + { + scheme MRT + pass + { + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + param_named ambient float4 1 1 1 1 + } + fragment_program_ref Ogre/MRTtest/scenefp + { + } + + texture_unit + { + texture ogrelogo.png + } + + } + } +} + + +fragment_program Ogre/MRTtest/quadfp/HLSL hlsl +{ + source mrttestfp.hlsl + entry_point mainfp_quad + target ps_2_0 +} + +fragment_program Ogre/MRTtest/quadfp/GLSL glsl +{ + source mrttestfp_quad.glsl + + default_params + { + param_named rt0 int 0 + param_named rt1 int 1 + param_named rt2 int 2 + param_named rt3 int 3 + } +} + +fragment_program Ogre/MRTtest/quadfp/GLSLES glsles +{ + source mrttestfp_quad.glsles + + default_params + { + param_named rt0 int 0 + param_named rt1 int 1 + param_named rt2 int 2 + param_named rt3 int 3 + } +} + +fragment_program Ogre/MRTtest/quadfp unified +{ + delegate Ogre/MRTtest/quadfp/HLSL + delegate Ogre/MRTtest/quadfp/GLSL + delegate Ogre/MRTtest/quadfp/GLSLES +} + + +// Quad material +material Ogre/MRTtest/quad +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_NoCG_vp + { + } + + fragment_program_ref Ogre/MRTtest/quadfp + { + } + + texture_unit RT0 + { + tex_address_mode clamp + } + texture_unit RT1 + { + tex_address_mode clamp + } + texture_unit RT2 + { + tex_address_mode clamp + } + texture_unit RT3 + { + tex_address_mode clamp + } + + + } + } +} diff --git a/res/dist/media/materials/scripts/MotionBlur.material b/res/dist/media/materials/scripts/MotionBlur.material new file mode 100644 index 00000000000..67db90f7c8e --- /dev/null +++ b/res/dist/media/materials/scripts/MotionBlur.material @@ -0,0 +1,101 @@ +fragment_program Ogre/Compositor/Combine_Cg_fp cg +{ + source Combine_fp.cg + profiles ps_2_0 arbfp1 + entry_point Combine_fp + + default_params + { + param_named blur float 0.8 + } +} + +fragment_program Ogre/Compositor/Combine_GLSLES_fp glsles +{ + source Combine_fp.glsles + default_params + { + param_named blur float 0.8 + param_named RT int 0 + param_named Sum int 1 + } +} + +fragment_program Ogre/Compositor/Combine_fp unified +{ + delegate Ogre/Compositor/Combine_GLSLES_fp + delegate Ogre/Compositor/Combine_Cg_fp +} + +material Ogre/Compositor/Combine +{ + technique + { + pass + { + depth_check off + + fragment_program_ref Ogre/Compositor/Combine_fp + { + } + + vertex_program_ref Ogre/Compositor/StdQuad_vp + { + } + + texture_unit RT + { + tex_address_mode clamp + filtering linear linear none + tex_coord_set 0 + } + + texture_unit SUM + { + tex_address_mode clamp + filtering linear linear none + tex_coord_set 0 + } + } + } +} + +material Ogre/Compositor/Copyback +{ + technique + { + pass + { + lighting off + depth_check off + + texture_unit Temp + { + tex_address_mode clamp + filtering linear linear none + colour_op replace + tex_coord_set 0 + } + } + } +} + +material Ogre/Compositor/MotionBlur +{ + technique + { + pass + { + lighting off + depth_check off + + texture_unit Sum + { + tex_address_mode clamp + filtering linear linear none + colour_op replace + tex_coord_set 0 + } + } + } +} diff --git a/res/dist/media/materials/scripts/NightVision.material b/res/dist/media/materials/scripts/NightVision.material new file mode 100644 index 00000000000..fec3d4bd1b8 --- /dev/null +++ b/res/dist/media/materials/scripts/NightVision.material @@ -0,0 +1,49 @@ +fragment_program Ogre/Compositor/NightVisionFP cg +{ + source NightVisionFP.cg + entry_point NightVision_ps + profiles ps_4_0 ps_2_0 arbfp1 + + default_params + { + param_named lum float4 0.30 0.59 0.11 0.0 + param_named_auto time time_0_1 1 + } +} + +material Ogre/Compositor/NightVision +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + fragment_program_ref Ogre/Compositor/NightVisionFP + { + + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + texture_unit noise + { + texture Random3D.dds 3d + tex_address_mode wrap + tex_coord_set 1 + } + } + } +} diff --git a/res/dist/media/materials/scripts/Ocean.controls b/res/dist/media/materials/scripts/Ocean.controls new file mode 100644 index 00000000000..07f2481aeff --- /dev/null +++ b/res/dist/media/materials/scripts/Ocean.controls @@ -0,0 +1,90 @@ +[1. Ocean2 Cg] +material = Ocean2_Cg +control = Wavelet Scale, BumpScale, GPU_VERTEX, 0, 2, 0 +control = Texture Scale X, textureScale, GPU_VERTEX, 0, 40, 0 +control = Texture Scale Y, textureScale, GPU_VERTEX, 0, 40, 1 +control = Wavelet Speed X, bumpSpeed, GPU_VERTEX, -0.1, 0.1, 0 +control = Wavelet Speed Y, bumpSpeed, GPU_VERTEX, -0.1, 0.1, 1 +control = Wave Frequency, waveFreq, GPU_VERTEX, 0, 0.05, 0 +control = Wave Amplitude, waveAmp, GPU_VERTEX, 0, 25, 0 + +control = Deep Color [Red], deepColor, GPU_FRAGMENT, 0, 1, 0 +control = Deep Color [Green], deepColor, GPU_FRAGMENT, 0, 1, 1 +control = Deep Color [Blue], deepColor, GPU_FRAGMENT, 0, 1, 2 + +control = Shallow Color [Red], shallowColor, GPU_FRAGMENT, 0, 1, 0 +control = Shallow Color [Green], shallowColor, GPU_FRAGMENT, 0, 1, 1 +control = Shallow Color [Blue], shallowColor, GPU_FRAGMENT, 0, 1, 2 + +control = Reflection Color [Red], reflectionColor, GPU_FRAGMENT, 0, 1, 0 +control = Reflection Color [Green], reflectionColor, GPU_FRAGMENT, 0, 1, 1 +control = Reflection Color [Blue], reflectionColor, GPU_FRAGMENT, 0, 1, 2 + +control = Reflection Amount, reflectionAmount, GPU_FRAGMENT, 0, 1, 0 +control = Reflection Blur, reflectionBlur, GPU_FRAGMENT, 0, 8, 0 +control = Water Amount, waterAmount, GPU_FRAGMENT, 0, 1, 0 +control = Fresnel Power, fresnelPower, GPU_FRAGMENT, 0, 10, 0 +control = Fresnel Bias, fresnelBias, GPU_FRAGMENT, 0, 1, 0 +control = HDR Mulitplier, hdrMultiplier, GPU_FRAGMENT, 0, 2, 0 + +[1a. Ocean2 HLSL/GLSL] +material = Ocean2_HLSL_GLSL +control = Wavelet Scale, BumpScale, GPU_VERTEX, 0, 2, 0 +control = Texture Scale X, textureScale, GPU_VERTEX, 0, 40, 0 +control = Texture Scale Y, textureScale, GPU_VERTEX, 0, 40, 1 +control = Wavelet Speed X, bumpSpeed, GPU_VERTEX, -0.1, 0.1, 0 +control = Wavelet Speed Y, bumpSpeed, GPU_VERTEX, -0.1, 0.1, 1 +control = Wave Frequency, waveFreq, GPU_VERTEX, 0, 0.05, 0 +control = Wave Amplitude, waveAmp, GPU_VERTEX, 0, 25, 0 + +control = Deep Color [Red], deepColor, GPU_FRAGMENT, 0, 1, 0 +control = Deep Color [Green], deepColor, GPU_FRAGMENT, 0, 1, 1 +control = Deep Color [Blue], deepColor, GPU_FRAGMENT, 0, 1, 2 + +control = Shallow Color [Red], shallowColor, GPU_FRAGMENT, 0, 1, 0 +control = Shallow Color [Green], shallowColor, GPU_FRAGMENT, 0, 1, 1 +control = Shallow Color [Blue], shallowColor, GPU_FRAGMENT, 0, 1, 2 + +control = Reflection Color [Red], reflectionColor, GPU_FRAGMENT, 0, 1, 0 +control = Reflection Color [Green], reflectionColor, GPU_FRAGMENT, 0, 1, 1 +control = Reflection Color [Blue], reflectionColor, GPU_FRAGMENT, 0, 1, 2 + +control = Reflection Amount, reflectionAmount, GPU_FRAGMENT, 0, 1, 0 +control = Reflection Blur, reflectionBlur, GPU_FRAGMENT, 0, 8, 0 +control = Water Amount, waterAmount, GPU_FRAGMENT, 0, 1, 0 +control = Fresnel Power, fresnelPower, GPU_FRAGMENT, 0, 10, 0 +control = Fresnel Bias, fresnelBias, GPU_FRAGMENT, 0, 1, 0 +control = HDR Mulitplier, hdrMultiplier, GPU_FRAGMENT, 0, 2, 0 + +[2. Ocean1 HLSL/GLSL] +material = OceanHLSL_GLSL +control = scale x, scale, GPU_VERTEX, 0, 0.1, 0 +control = scale y, scale, GPU_VERTEX, 0, 0.1, 1 +control = scale z, scale, GPU_VERTEX, 0, 0.1, 2 +control = Wave Speed X, waveSpeed, GPU_VERTEX, 0, 1, 0 +control = Wave Speed Y, waveSpeed, GPU_VERTEX, 0, 1, 1 +control = Noise Speed, noiseSpeed, GPU_VERTEX, 0, 1, 0 + +control = Fade Bias, fadeBias, GPU_FRAGMENT, 0, 1, 0 +control = Fade Exponent, fadeExp, GPU_FRAGMENT, 0, 20, 0 +control = Water Color (r), waterColor, GPU_FRAGMENT, 0, 1, 0 +control = Water Color (g), waterColor, GPU_FRAGMENT, 0, 1, 1 +control = Water Color (b), waterColor, GPU_FRAGMENT, 0, 1, 2 + +[3. Ocean1 Cg] +material = OceanCg +control = scale x, scale, GPU_VERTEX, 0, 0.1, 0 +control = scale y, scale, GPU_VERTEX, 0, 0.1, 1 +control = scale z, scale, GPU_VERTEX, 0, 0.1, 2 +control = Wave Speed X, waveSpeed, GPU_VERTEX, 0, 1, 0 +control = Wave Speed Y, waveSpeed, GPU_VERTEX, 0, 1, 1 +control = Noise Speed, noiseSpeed, GPU_VERTEX, 0, 1, 0 + +control = Fade Bias, fadeBias, GPU_FRAGMENT, 0, 1, 0 +control = Fade Exponent, fadeExp, GPU_FRAGMENT, 0, 20, 0 +control = Water Color (r), waterColor, GPU_FRAGMENT, 0, 1, 0 +control = Water Color (g), waterColor, GPU_FRAGMENT, 0, 1, 1 +control = Water Color (b), waterColor, GPU_FRAGMENT, 0, 1, 2 + + + diff --git a/res/dist/media/materials/scripts/Ocean.material b/res/dist/media/materials/scripts/Ocean.material new file mode 100644 index 00000000000..84514fe6193 --- /dev/null +++ b/res/dist/media/materials/scripts/Ocean.material @@ -0,0 +1,618 @@ +vertex_program HLSL/OceanVS hlsl +{ + source oceanHLSL_Cg.vert + entry_point main + target vs_1_1 + + + default_params + { + param_named_auto worldViewProj_matrix worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + param_named scale float3 0.012 0.005 0.03 + param_named_auto time_0_X time_0_x 100.0 + } +} + +fragment_program HLSL/OceanFS hlsl +{ + source oceanHLSL_Cg.frag + entry_point main + target ps_2_0 + +} + +vertex_program HLSL4/OceanVS hlsl +{ + source oceanHLSL_Cg.vert + entry_point main + target vs_4_0 + enable_backwards_compatibility true + + + default_params + { + param_named_auto worldViewProj_matrix worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + param_named scale float3 0.012 0.005 0.03 + param_named_auto time_0_X time_0_x 100.0 + } +} + +fragment_program HLSL4/OceanFS hlsl +{ + source oceanHLSL_Cg.frag + entry_point main + target ps_4_0 + enable_backwards_compatibility true +} + +vertex_program GLSL/OceanVS glsl +{ + source oceanGLSL.vert + + default_params + { + param_named_auto eyePosition camera_position_object_space + param_named scale float3 0.012 0.005 0.03 + param_named_auto time_0_X time_0_x 100.0 + } +} + +fragment_program GLSL/OceanFS glsl +{ + source oceanGLSL.frag + + default_params + { + param_named Noise int 0 + param_named skyBox int 1 + } +} + +material OceanHLSL_GLSL +{ + technique HLSL + { + pass + { + vertex_program_ref HLSL/OceanVS + { + param_named waveSpeed float2 0.0 0.168 + param_named noiseSpeed float 0.155 + } + + fragment_program_ref HLSL/OceanFS + { + param_named fadeBias float 0.336 + param_named fadeExp float 5.546 + param_named waterColor float4 0.0 0.244 0.395 1.0 + } + + texture_unit + { + texture NoiseVolume.dds 3d + tex_coord_set 0 + filtering linear linear none + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + tex_coord_set 1 + } + + } + + } + + technique HLSL4 + { + pass + { + vertex_program_ref HLSL4/OceanVS + { + param_named waveSpeed float2 0.0 0.168 + param_named noiseSpeed float 0.155 + } + + fragment_program_ref HLSL4/OceanFS + { + param_named fadeBias float 0.336 + param_named fadeExp float 5.546 + param_named waterColor float4 0.0 0.244 0.395 1.0 + } + + texture_unit + { + texture NoiseVolume.dds 3d + tex_coord_set 0 + filtering linear linear none + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + tex_coord_set 1 + } + + } + + } + + technique GLSL + { + pass + { + vertex_program_ref GLSL/OceanVS + { + param_named waveSpeed float2 0.0 0.168 + param_named noiseSpeed float 0.155 + } + + fragment_program_ref GLSL/OceanFS + { + param_named fadeBias float 0.336 + param_named fadeExp float 5.546 + param_named waterColor float4 0.0 0.244 0.395 1.0 + } + + texture_unit + { + texture NoiseVolume.dds 3d + tex_coord_set 0 + filtering linear linear none + tex_address_mode wrap + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + tex_coord_set 1 + } + + } + + } +} + + +vertex_program Cg/OceanVS cg +{ + source oceanHLSL_Cg.vert + entry_point main + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj_matrix worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + param_named scale float3 0.012 0.005 0.03 + param_named_auto time_0_X time_0_x 100.0 + } +} + +fragment_program Cg/OceanFS cg +{ + source oceanHLSL_Cg.frag + entry_point main + profiles ps_4_0 ps_2_0 arbfp1 + +} + +material OceanCg +{ + technique + { + pass + { + vertex_program_ref Cg/OceanVS + { + param_named waveSpeed float2 0.0 0.168 + param_named noiseSpeed float 0.155 + } + + fragment_program_ref Cg/OceanFS + { + param_named fadeBias float 0.336 + param_named fadeExp float 5.546 + param_named waterColor float4 0.0 0.244 0.395 1.0 + } + + texture_unit + { + texture NoiseVolume.dds 3d + tex_coord_set 0 + filtering linear linear none + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + tex_coord_set 1 + } + + } + + } +} + + +vertex_program Cg/Ocean2VS cg +{ + source Ocean2HLSL_Cg.vert + entry_point main + profiles vs_4_0 vs_1_1 arbvp1 + + + default_params + { + param_named_auto WorldViewProj worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + } +} + +fragment_program Cg/Ocean2FS cg +{ + source Ocean2HLSL_Cg.frag + entry_point main + profiles ps_4_0 ps_2_0 arbfp1 + +} + +material Ocean2_Cg +{ + technique + { + pass + { + vertex_program_ref Cg/Ocean2VS + { + param_named BumpScale float 0.2 + param_named textureScale float2 25 26 + param_named bumpSpeed float2 0.015 0.005 + param_named_auto time time_0_x 100.0 + param_named waveFreq float 0.028 + param_named waveAmp float 1.8 + } + + fragment_program_ref Cg/Ocean2FS + { + param_named deepColor float4 0 0.3 0.5 1.0 + param_named shallowColor float4 0 1 1 1.0 + param_named reflectionColor float4 0.95 1 1 1.0 + param_named reflectionAmount float 1.0 + param_named reflectionBlur float 0.0 + param_named waterAmount float 0.3 + param_named fresnelPower float 5.0 + param_named fresnelBias float 0.328 + param_named hdrMultiplier float 0.471 + } + + texture_unit + { + texture waves2.dds + tex_coord_set 0 + filtering linear linear linear + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + tex_coord_set 1 + filtering linear linear linear + } + + } + + } +} + + +vertex_program HLSL/Ocean2VS hlsl +{ + source Ocean2HLSL_Cg.vert + entry_point main + target vs_1_1 + + + default_params + { + param_named_auto WorldViewProj worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + } +} + +fragment_program HLSL/Ocean2FS hlsl +{ + source Ocean2HLSL_Cg.frag + entry_point main + target ps_2_0 + +} + +vertex_program HLSL4/Ocean2VS hlsl +{ + source Ocean2HLSL_Cg.vert + entry_point main + target vs_4_0 + enable_backwards_compatibility true + + default_params + { + param_named_auto WorldViewProj worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + } +} + +fragment_program HLSL4/Ocean2FS hlsl +{ + source Ocean2HLSL_Cg.frag + entry_point main + target ps_4_0 + enable_backwards_compatibility true +} + +vertex_program GLSL/Ocean2VS glsl +{ + source Ocean2GLSL.vert + +} + +fragment_program GLSL/Ocean2FS glsl +{ + source Ocean2GLSL.frag +} + +vertex_program GLSLES/Ocean2VS glsles +{ + source Ocean2GLSLES.vert +} + +fragment_program GLSLES/Ocean2FS glsles +{ + source Ocean2GLSLES.frag + default_params + { + param_named NormalMap int 0 + param_named EnvironmentMap int 1 + } +} + +material Ocean2_HLSL_GLSL +{ + technique HLSL + { + pass + { + vertex_program_ref HLSL/Ocean2VS + { + param_named BumpScale float 0.2 + param_named textureScale float2 25 26 + param_named bumpSpeed float2 0.015 0.005 + param_named_auto time time_0_x 100.0 + param_named waveFreq float 0.028 + param_named waveAmp float 1.8 + } + + fragment_program_ref HLSL/Ocean2FS + { + param_named deepColor float4 0 0.3 0.5 1.0 + param_named shallowColor float4 0 1 1 1.0 + param_named reflectionColor float4 0.95 1 1 1.0 + param_named reflectionAmount float 1.0 + param_named reflectionBlur float 0.0 + param_named waterAmount float 0.3 + param_named fresnelPower float 5.0 + param_named fresnelBias float 0.328 + param_named hdrMultiplier float 0.471 + } + + texture_unit + { + texture waves2.dds + tex_coord_set 0 + filtering linear linear linear + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + filtering linear linear linear + tex_coord_set 1 + } + + } + + } + + technique HLSL4 + { + pass + { + vertex_program_ref HLSL4/Ocean2VS + { + param_named BumpScale float 0.2 + param_named textureScale float2 25 26 + param_named bumpSpeed float2 0.015 0.005 + param_named_auto time time_0_x 100.0 + param_named waveFreq float 0.028 + param_named waveAmp float 1.8 + } + + fragment_program_ref HLSL4/Ocean2FS + { + param_named deepColor float4 0 0.3 0.5 1.0 + param_named shallowColor float4 0 1 1 1.0 + param_named reflectionColor float4 0.95 1 1 1.0 + param_named reflectionAmount float 1.0 + param_named reflectionBlur float 0.0 + param_named waterAmount float 0.3 + param_named fresnelPower float 5.0 + param_named fresnelBias float 0.328 + param_named hdrMultiplier float 0.471 + } + + texture_unit + { + texture waves2.dds + tex_coord_set 0 + filtering linear linear linear + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + filtering linear linear linear + tex_coord_set 1 + } + + } + + } + + technique GLSL + { + pass + { + vertex_program_ref GLSL/Ocean2VS + { + param_named_auto eyePosition camera_position_object_space + param_named_auto time time_0_x 100.0 + param_named BumpScale float 0.2 + param_named textureScale float2 25 26 + param_named bumpSpeed float2 0.015 0.005 + param_named waveFreq float 0.028 + param_named waveAmp float 1.8 + } + + fragment_program_ref GLSL/Ocean2FS + { + param_named deepColor float4 0 0.3 0.5 1.0 + param_named shallowColor float4 0 1 1 1.0 + param_named reflectionColor float4 0.95 1 1 1.0 + param_named reflectionAmount float 1.0 + param_named reflectionBlur float 0.0 + param_named waterAmount float 0.3 + param_named fresnelPower float 5.0 + param_named fresnelBias float 0.328 + param_named hdrMultiplier float 0.471 + param_named NormalMap int 0 + param_named EnvironmentMap int 1 + } + + texture_unit + { + texture waves2.dds + tex_coord_set 0 + filtering linear linear linear + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + tex_coord_set 1 + filtering linear linear linear + } + + } + + } + + technique GLSLES + { + pass + { + vertex_program_ref GLSLES/Ocean2VS + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto eyePosition camera_position_object_space + param_named_auto time time_0_x 100.0 + param_named BumpScale float 0.2 + param_named textureScale float2 25 26 + param_named bumpSpeed float2 0.015 0.005 + param_named waveFreq float 0.028 + param_named waveAmp float 1.8 + } + + fragment_program_ref GLSLES/Ocean2FS + { + param_named deepColor float4 0 0.3 0.5 1.0 + param_named shallowColor float4 0 1 1 1.0 + param_named reflectionColor float4 0.95 1 1 1.0 + param_named reflectionAmount float 1.0 + param_named reflectionBlur float 0.0 + param_named waterAmount float 0.3 + param_named fresnelPower float 5.0 + param_named fresnelBias float 0.328 + param_named hdrMultiplier float 0.471 + param_named NormalMap int 0 + param_named EnvironmentMap int 1 + } + + texture_unit + { + texture waves2.dds + tex_coord_set 0 + filtering linear linear linear + } + + texture_unit + { + cubic_texture morning.jpg combinedUVW + tex_address_mode clamp + tex_coord_set 1 + filtering linear linear linear + } + + } + + } +} + +material SkyBox +{ + technique + { + pass + { + lighting off + depth_write off + depth_check off + + texture_unit + { + cubic_texture morning.jpg separateUV + tex_address_mode clamp + } + } + } +} + +material LightFlare +{ + technique + { + pass + { + lighting off + scene_blend add + depth_write off + + texture_unit + { + texture flare.png + } + } + } +} + + diff --git a/res/dist/media/materials/scripts/OffsetMapping.material b/res/dist/media/materials/scripts/OffsetMapping.material new file mode 100644 index 00000000000..867c6484689 --- /dev/null +++ b/res/dist/media/materials/scripts/OffsetMapping.material @@ -0,0 +1,447 @@ +// Bump map with Parallax offset vertex program, support for this is required +vertex_program Examples/OffsetMappingVPCg cg +{ + source OffsetMapping.cg + entry_point main_vp + profiles vs_1_1 arbvp1 +} + +// Bump map with parallax fragment program +fragment_program Examples/OffsetMappingFPCg cg +{ + source OffsetMapping.cg + entry_point main_fp + profiles ps_2_0 arbfp1 +} + +// Bump map with Parallax offset vertex program, support for this is required +vertex_program Examples/OffsetMappingVPShaderModel4 cg +{ + source OffsetMapping.cg + entry_point main_vp + profiles vs_4_0 +} + +// Bump map with parallax fragment program +fragment_program Examples/OffsetMappingFPShaderModel4 cg +{ + source OffsetMapping.cg + entry_point main_fp + profiles ps_4_0 +} + + +// Bump map with parallax fragment program +fragment_program Examples/OffsetMappingPSAsm asm +{ + source OffsetMapping_specular.asm + // sorry, only for ps_1_4 and above:) + syntax ps_1_4 + default_params + { + // Parallax Height scale and bias + param_indexed 2 float4 0.04 -0.02 1 0 + } +} + +// Bump map with parallax fragment program +fragment_program Examples/OffsetMappingPSGLSLES glsles +{ + source OffsetMapping_specular.glsles + profiles glsles + default_params + { + // Parallax Height scale and bias + param_named scaleBias float4 0.04 -0.02 1 0 + } +} + +// Bump map with Parallax offset vertex program, support for this is required +vertex_program Examples/OffsetMappingVPGLSLES glsles +{ + source OffsetMappingVp.glsles + profiles glsles +} + +// Bump map with parallax fragment program +fragment_program Examples/OffsetMappingFPGLSLES glsles +{ + source OffsetMappingFp.glsles + profiles glsles + default_params + { + // assign samplers as required by GLSL + param_named normalHeightMap int 0 + param_named diffuseMap int 1 + } +} + +vertex_program Examples/OffsetMappingVP unified +{ + delegate Examples/OffsetMappingVPGLSLES + delegate Examples/OffsetMappingVPCg +} + +fragment_program Examples/OffsetMappingFP unified +{ + delegate Examples/OffsetMappingFPGLSLES + delegate Examples/OffsetMappingFPCg +} + +fragment_program Examples/OffsetMappingPS unified +{ + delegate Examples/OffsetMappingPSGLSLES + delegate Examples/OffsetMappingPSAsm +} + + +material Examples/OffsetMapping/Specular +{ + technique ShaderModel4 + { + // ambient / depth + pass + { + illumination_stage ambient + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureCgSm4 + { + param_named_auto worldViewProj worldviewproj_matrix + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFpCgSm4ForAmbientOneTexture + { + } + + } + + // do the lighting and bump mapping with parallax pass + pass + { + illumination_stage per_light + scene_blend add + depth_write off + + // Vertex program reference + vertex_program_ref Examples/OffsetMappingVPShaderModel4 + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + } + + // Fragment program + fragment_program_ref Examples/OffsetMappingFPShaderModel4 + { + param_named_auto lightDiffuse light_diffuse_colour 0 + param_named_auto lightSpecular light_specular_colour 0 + // Parallax Height scale and bias + param_named scaleBias float4 0.04 -0.02 1 0 + } + + // Normal + height(alpha) map + texture_unit + { + texture rockwall_NH.tga + tex_coord_set 0 + } + + // Base diffuse texture map + texture_unit + { + texture rockwall.tga + tex_coord_set 1 + } + } + } + + technique GLES + { + // ambient / depth + pass + { + illumination_stage ambient + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + } + fragment_program_ref Ogre/BasicFragmentPrograms/PassthroughFP + { + } + + } + // do the lighting and bump mapping with parallax pass + pass + { + illumination_stage per_light + scene_blend add + depth_write off + + // Vertex program reference + vertex_program_ref Examples/OffsetMappingVP + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + } + + // Fragment program + fragment_program_ref Examples/OffsetMappingFP + { + param_named_auto lightDiffuse light_diffuse_colour 0 + param_named_auto lightSpecular light_specular_colour 0 + // Parallax Height scale and bias + param_named scaleBias float4 0.04 -0.02 1 0 + } + + // Normal + height(alpha) map + texture_unit + { + texture rockwall_NH.tga + tex_coord_set 0 + } + + // Base diffuse texture map + texture_unit + { + texture rockwall.tga + tex_coord_set 1 + } + } + } + + technique gl dx9 + { + // ambient / depth + pass + { + illumination_stage ambient + vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTextureUnified + { + } + + } + // do the lighting and bump mapping with parallax pass + pass + { + illumination_stage per_light + scene_blend add + depth_write off + + // Vertex program reference + vertex_program_ref Examples/OffsetMappingVP + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + } + + // Fragment program + fragment_program_ref Examples/OffsetMappingFP + { + param_named_auto lightDiffuse light_diffuse_colour 0 + param_named_auto lightSpecular light_specular_colour 0 + // Parallax Height scale and bias + param_named scaleBias float4 0.04 -0.02 1 0 + } + + // Normal + height(alpha) map + texture_unit + { + texture rockwall_NH.tga + tex_coord_set 0 + } + + // Base diffuse texture map + texture_unit + { + texture rockwall.tga + tex_coord_set 1 + } + } + } + + // This is the preferred technique which uses both vertex and + // fragment programs, supports coloured lights + technique + { + // do the lighting and bump mapping with parallax pass + pass + { + + // Vertex program reference + vertex_program_ref Examples/OffsetMappingVP + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + } + + // Fragment program + fragment_program_ref Examples/OffsetMappingPS + { + param_indexed_auto 0 light_diffuse_colour 0 + param_indexed_auto 1 light_specular_colour 0 + // Parallax Height scale and bias +// param_indexed 2 float4 0.04 -0.02 1 0 + } + + // Normal + height(alpha) map + texture_unit + { + texture rockwall_NH.tga + tex_coord_set 0 + } + + // Base diffuse texture map + texture_unit + { + texture rockwall.tga + tex_coord_set 1 + } + } + } + + // Simple no-shader fallback + technique + { + pass + { + // Base diffuse texture map + texture_unit + { + texture rockwall.tga + } + } + } + +} + + + +// Single-pass offset mapping with shadows +vertex_program Examples/OffsetMappingIntegratedShadowsVPhlsl hlsl +{ + source OffsetMapping.hlsl + entry_point integratedshadows_vp + target vs_2_0 +} +vertex_program Examples/OffsetMappingIntegratedShadowsVPglsl glsl +{ + source OffsetMappingVp.glsl +} + +vertex_program Examples/OffsetMappingIntegratedShadowsVPglsles glsles +{ + source OffsetMappingShadowsVp.glsles +} + +// Single-pass offset mapping with shadows +fragment_program Examples/OffsetMappingIntegratedShadowsFPhlsl hlsl +{ + source OffsetMapping.hlsl + entry_point integratedshadows_fp + target ps_2_0 +} +fragment_program Examples/OffsetMappingIntegratedShadowsFPglsl glsl +{ + source OffsetMappingFp.glsl + default_params + { + // assign samplers as required by GLSL + param_named normalHeightMap int 0 + param_named diffuseMap int 1 + param_named shadowMap1 int 2 + param_named shadowMap2 int 3 + } +} +fragment_program Examples/OffsetMappingIntegratedShadowsFPglsles glsles +{ + source OffsetMappingShadowsFp.glsles + default_params + { + // assign samplers as required by GLSL ES + param_named normalHeightMap int 0 + param_named diffuseMap int 1 + param_named shadowMap1 int 2 + param_named shadowMap2 int 3 + } +} +// Single-pass offset mapping with shadows +vertex_program Examples/OffsetMappingIntegratedShadowsVP unified +{ + delegate Examples/OffsetMappingIntegratedShadowsVPhlsl + delegate Examples/OffsetMappingIntegratedShadowsVPglsl + delegate Examples/OffsetMappingIntegratedShadowsVPglsles +} +// Single-pass offset mapping with shadows +fragment_program Examples/OffsetMappingIntegratedShadowsFP unified +{ + delegate Examples/OffsetMappingIntegratedShadowsFPhlsl + delegate Examples/OffsetMappingIntegratedShadowsFPglsl + delegate Examples/OffsetMappingIntegratedShadowsFPglsles +} + + + +material Examples/OffsetMapping/IntegratedShadows +{ + + technique + { + // do the lighting and bump mapping with parallax pass + pass + { + + // Vertex program reference + vertex_program_ref Examples/OffsetMappingIntegratedShadowsVP + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto spotDirection light_direction_object_space 0 + + param_named_auto lightPosition1 light_position_object_space 1 + param_named_auto spotDirection1 light_direction_object_space 1 + // shadow texture projections + param_named_auto worldMatrix world_matrix + param_named_auto texViewProj1 texture_viewproj_matrix 0 + param_named_auto texViewProj2 texture_viewproj_matrix 1 + } + + // Fragment program + fragment_program_ref Examples/OffsetMappingIntegratedShadowsFP + { + param_named_auto lightDiffuse light_diffuse_colour 0 + param_named_auto spotParams spotlight_params 0 + + param_named_auto lightDiffuse1 light_diffuse_colour 1 + param_named_auto spotParams1 spotlight_params 1 + // Parallax Height scale and bias + param_named scaleBias float4 0.04 -0.02 1 0 + } + + // Normal + height(alpha) map + texture_unit + { + texture rockwall_NH.tga + tex_coord_set 0 + } + + // Base diffuse texture map + texture_unit + { + texture rockwall.tga + tex_coord_set 1 + } + + // shadowmap 1 + texture_unit + { + content_type shadow + } + // shadowmap 2 + texture_unit + { + content_type shadow + } + } + } +} diff --git a/res/dist/media/materials/scripts/Ogre.material b/res/dist/media/materials/scripts/Ogre.material new file mode 100644 index 00000000000..0d408805118 --- /dev/null +++ b/res/dist/media/materials/scripts/Ogre.material @@ -0,0 +1,66 @@ +material Ogre/Earring +{ + technique + { + pass + { + ambient 0.7 0.7 0 + diffuse 0.7 0.7 0 + + texture_unit + { + texture spheremap.png + colour_op_ex add src_texture src_current + colour_op_multipass_fallback one one + env_map spherical + } + } + } +} + +material Ogre/Skin +{ + technique + { + pass + { + ambient 0.3 0.8 0.3 + + texture_unit + { + texture GreenSkin.jpg + tex_address_mode mirror + } + } + } +} + +material Ogre/Tusks +{ + technique + { + pass + { + ambient 0.7 0.7 0.6 + + texture_unit + { + texture tusk.jpg + scale 0.2 0.2 + } + } + } +} + +material Ogre/Eyes +{ + technique + { + pass + { + ambient 1 0.4 0.4 + diffuse 1 0.7 0 + emissive 0.3 0.1 0 + } + } +} \ No newline at end of file diff --git a/res/dist/media/materials/scripts/OldMovie.material b/res/dist/media/materials/scripts/OldMovie.material new file mode 100644 index 00000000000..dd57c37c12e --- /dev/null +++ b/res/dist/media/materials/scripts/OldMovie.material @@ -0,0 +1,85 @@ +fragment_program Ogre/Compositor/OldMovie_Cg_FP cg +{ + source OldMovieFP.cg + entry_point OldMovie_ps + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/OldMovie_GLSLES_FP glsles +{ + source OldMovieFP.glsles + default_params + { + param_named RT int 0 + param_named SplotchesTx int 1 + param_named Texture2 int 2 + param_named SepiaTx int 3 + } +} + +fragment_program Ogre/Compositor/OldMovieFP unified +{ + delegate Ogre/Compositor/OldMovie_GLSLES_FP + delegate Ogre/Compositor/OldMovie_Cg_FP +} + +material Ogre/Compositor/OldMovie +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + fragment_program_ref Ogre/Compositor/OldMovieFP + { + param_named_auto time_cycle_period time 20 + param_named flicker float 0.4 + param_named DirtFrequency float 0.0005 + param_named luminance float3 0.30 0.59 0.11 + param_named frameJitter float 0.004 + param_named lumiShift float 0.03 + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + texture_unit SplotchesTx + { + texture 8x8PagesSplotches2.png 2d + tex_coord_set 1 + tex_address_mode wrap + filtering trilinear + } + + texture_unit + { + texture 1D_Noise.png 1d + tex_coord_set 2 + tex_address_mode wrap + filtering point point none + } + + + texture_unit SepiaTx + { + texture Sepia1D.tga 1d + tex_coord_set 3 + tex_address_mode mirror + filtering point point none + } + + } + } +} diff --git a/res/dist/media/materials/scripts/OldTV.material b/res/dist/media/materials/scripts/OldTV.material new file mode 100644 index 00000000000..c4ba1911456 --- /dev/null +++ b/res/dist/media/materials/scripts/OldTV.material @@ -0,0 +1,59 @@ +fragment_program Ogre/Compositor/OldTV_FP cg +{ + source OldTV.cg + entry_point OldTV_ps + profiles ps_2_0 arbfp1 +} + +material Ogre/Compositor/OldTV +{ + technique + { + + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + fragment_program_ref Ogre/Compositor/OldTV_FP + { + param_named_auto time_0_X time_0_x 120 + param_named_auto sin_time_0_X sintime_0_x 120 + + param_named distortionFreq float 2.7 + param_named distortionScale float 2.5 + param_named distortionRoll float 0.93 + param_named interference float 0.5 + param_named frameLimit float 0.40 + param_named frameShape float 0.26 + param_named frameSharpness float 6.0 + } + + texture_unit 0 + { + tex_coord_set 0 + tex_address_mode clamp + filtering linear linear linear + } + + texture_unit 1 + { + texture Random3D.dds 3d + tex_coord_set 1 + tex_address_mode wrap + filtering linear linear linear + } + + texture_unit 2 + { + texture NoiseVolume.dds 3d + tex_coord_set 2 + tex_address_mode wrap + filtering linear linear linear + } + } + } +} diff --git a/res/dist/media/materials/scripts/ParticleGS.material b/res/dist/media/materials/scripts/ParticleGS.material new file mode 100644 index 00000000000..623be689c9d --- /dev/null +++ b/res/dist/media/materials/scripts/ParticleGS.material @@ -0,0 +1,200 @@ +vertex_program Ogre/ParticleGS/GenerateVScg cg +{ + source ParticleGS.cg + entry_point GenerateParticles_VS + profiles vs_1_1 arbvp1 +} + +geometry_program Ogre/ParticleGS/GenerateGScg cg +{ + source ParticleGS.cg + entry_point GenerateParticles_GS + profiles gp4gp gpu_gp +} + +vertex_program Ogre/ParticleGS/DisplayVScg cg +{ + source ParticleGS.cg + entry_point DisplayParticles_VS + profiles vs_1_1 arbvp1 +} + +geometry_program Ogre/ParticleGS/DisplayGScg cg +{ + source ParticleGS.cg + entry_point DisplayParticles_GS + profiles gp4gp gpu_gp +} + +fragment_program Ogre/ParticleGS/DisplayPScg cg +{ + source ParticleGS.cg + entry_point DisplayParticles_PS + profiles ps_2_0 arbfp1 +} + +vertex_program Ogre/ParticleGS/GenerateVShlsl4 hlsl +{ + source ParticleGS.hlsl + entry_point GenerateParticles_VS + enable_backwards_compatibility no + target vs_4_0 +} + +geometry_program Ogre/ParticleGS/GenerateGShlsl4 hlsl +{ + source ParticleGS.hlsl + entry_point GenerateParticles_GS + enable_backwards_compatibility no + target gs_4_0 +} + +vertex_program Ogre/ParticleGS/DisplayVShlsl4 hlsl +{ + source ParticleGS.hlsl + entry_point DisplayParticles_VS + enable_backwards_compatibility no + target vs_4_0 +} + +geometry_program Ogre/ParticleGS/DisplayGShlsl4 hlsl +{ + source ParticleGS.hlsl + entry_point DisplayParticles_GS + enable_backwards_compatibility no + target gs_4_0 +} + +fragment_program Ogre/ParticleGS/DisplayPShlsl4 hlsl +{ + source ParticleGS.hlsl + entry_point DisplayParticles_PS + enable_backwards_compatibility no + target ps_4_0 +} + +//The material used to generate the particle system geometry +material Ogre/ParticleGS/Generate +{ + technique cg + { + pass + { + vertex_program_ref Ogre/ParticleGS/GenerateVScg + { + + } + + geometry_program_ref Ogre/ParticleGS/GenerateGScg + { + param_named frameGravity float3 0 -0.1 0 + param_named globalTime float 0.0 + param_named elapsedTime float 0.1 + param_named secondsPerFirework float 0.3 + } + + //This texture unit will be filled at runtime + texture_unit RandomTexture + { + tex_address_mode wrap + filtering none + } + } + } + technique hlsl4 + { + pass + { + vertex_program_ref Ogre/ParticleGS/GenerateVShlsl4 + { + + } + + geometry_program_ref Ogre/ParticleGS/GenerateGShlsl4 + { + param_named frameGravity float3 0 -0.1 0 + param_named globalTime float 0.0 + param_named elapsedTime float 0.1 + param_named secondsPerFirework float 0.3 + } + + //This texture unit will be filled at runtime + texture_unit RandomTexture + { + tex_address_mode wrap + filtering none + } + // This is needed if you render to a stream out buffer, otherwise, atleast DX 11 complains + depth_write off + depth_check off + } + } +} + +//The material used to display the generated particle system geometry +material Ogre/ParticleGS/Display +{ + technique cg + { + pass + { + depth_write off + + vertex_program_ref Ogre/ParticleGS/DisplayVScg + { + + } + + geometry_program_ref Ogre/ParticleGS/DisplayGScg + { + param_named_auto inverseView inverse_view_matrix + param_named_auto worldViewProj worldviewproj_matrix + } + + fragment_program_ref Ogre/ParticleGS/DisplayPScg + { + + } + + texture_unit + { + tex_coord_set 0 + texture particle.dds + } + + scene_blend alpha_blend + } + } + technique hlsl4 + { + pass + { + depth_write off + + vertex_program_ref Ogre/ParticleGS/DisplayVShlsl4 + { + + } + + geometry_program_ref Ogre/ParticleGS/DisplayGShlsl4 + { + param_named_auto inverseView inverse_view_matrix + param_named_auto worldViewProj worldviewproj_matrix + } + + fragment_program_ref Ogre/ParticleGS/DisplayPShlsl4 + { + + } + + texture_unit + { + tex_coord_set 0 + texture particle.dds + } + + scene_blend alpha_blend + } + } +} + diff --git a/res/dist/media/materials/scripts/Penguin.material b/res/dist/media/materials/scripts/Penguin.material new file mode 100644 index 00000000000..0cf6af33979 --- /dev/null +++ b/res/dist/media/materials/scripts/Penguin.material @@ -0,0 +1,13 @@ +material Penguin +{ + technique + { + pass + { + texture_unit + { + texture penguin.jpg + } + } + } +} diff --git a/res/dist/media/materials/scripts/Posterize.material b/res/dist/media/materials/scripts/Posterize.material new file mode 100644 index 00000000000..2f55e7d5be5 --- /dev/null +++ b/res/dist/media/materials/scripts/Posterize.material @@ -0,0 +1,46 @@ +fragment_program Ogre/Compositor/Posterize_Cg_FP cg +{ + source PosterizeFP.cg + entry_point Posterize_ps + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/Posterize_GLSLES_FP glsles +{ + source PosterizeFP.glsles +} + +fragment_program Ogre/Compositor/PosterizeFP unified +{ + delegate Ogre/Compositor/Posterize_GLSLES_FP + delegate Ogre/Compositor/Posterize_Cg_FP +} + +material Ogre/Compositor/Posterize +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + fragment_program_ref Ogre/Compositor/PosterizeFP + { + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + } + } +} diff --git a/res/dist/media/materials/scripts/RZR-002.material b/res/dist/media/materials/scripts/RZR-002.material new file mode 100644 index 00000000000..4b2dcc10d27 --- /dev/null +++ b/res/dist/media/materials/scripts/RZR-002.material @@ -0,0 +1,15 @@ + +material RZR-002 +{ + technique + { + pass + { + + texture_unit + { + texture RZR-002.png + } + } + } +} \ No newline at end of file diff --git a/res/dist/media/materials/scripts/RadialBlur.material b/res/dist/media/materials/scripts/RadialBlur.material new file mode 100644 index 00000000000..b2ed15d445b --- /dev/null +++ b/res/dist/media/materials/scripts/RadialBlur.material @@ -0,0 +1,49 @@ +//Cg Pixel Shader ps_2_0 +fragment_program Radial_Blur_Cg_ps cg +{ + source Radial_Blur_FP.cg + profiles ps_2_0 arbfp1 + entry_point main +} + +fragment_program Radial_Blur_GLSLES_ps glsles +{ + source Radial_Blur_FP.glsles +} + +fragment_program Radial_Blur_ps unified +{ + delegate Radial_Blur_GLSLES_ps + delegate Radial_Blur_Cg_ps +} + +//Effect: Radial Blur +material Ogre/Compositor/Radial_Blur +{ + technique + { + pass + { + //State: D3DRS_CULLMODE, Value : D3DCULL_NONE + cull_hardware none + cull_software none + depth_check off + + fragment_program_ref Radial_Blur_ps + { + param_named sampleDist float 1.0 + param_named sampleStrength float 2.2 + } + vertex_program_ref Ogre/Compositor/StdQuad_vp + { + } + + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/CreaseShading.cg b/res/dist/media/materials/scripts/SSAO/CreaseShading.cg new file mode 100644 index 00000000000..2e304ca74e7 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/CreaseShading.cg @@ -0,0 +1,65 @@ +// original sources found at Game Developer Magazine March 2008 + +void CreaseShading_fp +( + in float2 uv : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sNormal : register(s0), // xyz normal + depth [0, 1] + uniform sampler sPosition : register(s1), // view space position + uniform sampler sRandom : register(s2), // random texture sampler + uniform const float cRange, // the three(four) artistic parameters + uniform const float cBias, + uniform const float cAverager, + uniform const float cMinimumCrease, + uniform const float cKernelSize, // Bias for the kernel size, Hack for the fixed size 11x11 stipple kernel + uniform const float4 cViewportSize // (width, height, 1/width, 1/height) +) +{ + // get the view space position and normal of the fragment + const float3 fragmentPosition = tex2D(sPosition, uv).xyz; + const float3 fragmentNormal = tex2D(sNormal, uv).xyz; + + float totalGI = 0.0f; + + // a diamond shaped (45deg rotated square) stipple pattern around (0, 0) this will be used as offset for the samples + // O + // O O + // O O O + // O O O O + // O O X O O + // O O O O + // O O O + // O O + // O + // the algorith starts with the leftmost element and walks the diagonal to the topmost element + // a stippleSize of n yields (((n - 1) / 2)^2) - 1 samples + // the 'image' above has a stipple size of 11 'cuz it has 5 samples (minus + // the current fragment position and 4 gaps = 11. + + const int stippleSize = 11; // must be odd + for (int i = 0; i < (stippleSize + 1) / 2; i++) + { + float2 diagonalStart = float2(-(stippleSize - 1) / 2, 0) + i; + for(int j = 0; j < (stippleSize + 1) / 2; j++) + { + float2 sampleOffset = diagonalStart + float2(j, -j); + + float2 sampleUV = uv + (sampleOffset * cViewportSize.zw * cKernelSize); + float3 samplePos = tex2D(sPosition, sampleUV).xyz; + + float3 toCenter = samplePos - fragmentPosition; + float distance = length(toCenter); + + toCenter = normalize(toCenter); + float centerContrib = saturate((dot(toCenter, fragmentNormal) - cMinimumCrease) * cBias); + float rangeAttenuation = 1.0f - saturate(distance / cRange); + + totalGI += centerContrib * rangeAttenuation; + } + } + + totalGI /= cAverager; + oColor0 = 1 - float4(totalGI.xxx, 1); +} diff --git a/res/dist/media/materials/scripts/SSAO/CreaseShading.material b/res/dist/media/materials/scripts/SSAO/CreaseShading.material new file mode 100644 index 00000000000..fa1ead5d426 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/CreaseShading.material @@ -0,0 +1,57 @@ +fragment_program SSAO/CreaseShading_fp_hlsl hlsl +{ + source CreaseShading.cg + entry_point CreaseShading_fp + target ps_3_0 +} + +fragment_program SSAO/CreaseShading_fp_cg cg +{ + source CreaseShading.cg + entry_point CreaseShading_fp + profiles ps_2_x arbfp1 +} + +fragment_program SSAO/CreaseShading_fp unified +{ + delegate SSAO/CreaseShading_fp_hlsl + delegate SSAO/CreaseShading_fp_cg +} + +material SSAO/CreaseShading +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/CreaseShading_fp + { + param_named_auto cViewportSize viewport_size + } + + texture_unit // normals + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + + texture_unit // view space position + { + content_type compositor SSAO/GBuffer mrt 2 + tex_address_mode clamp + filtering none + } + + texture_unit // random texture will be replace by 11x11 stipple + { + texture rand1x32.png + tex_address_mode clamp + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/Crytek.cg b/res/dist/media/materials/scripts/SSAO/Crytek.cg new file mode 100644 index 00000000000..1d47409e020 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/Crytek.cg @@ -0,0 +1,88 @@ +void Crytek_fp +( + in float2 fragmentTC : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sSceneDepthSampler : register(s0), // depth = w component [0, 1] + uniform sampler sRotSampler4x4 : register(s1), // rotation sampler -> pseudo random spherical weighted sampling + uniform float4 cViewportSize, // auto param width/height/inv. width/inv. height + uniform float cFov, // vertical field of view in radians + uniform float farClipDistance, + uniform float nearClipDistance, + uniform float cSampleInScreenspace, // whether to sample in screen or world space + uniform float cSampleLengthScreenSpace, // The sample length in screen space [0, 1] + uniform float cSampleLengthWorldSpace, // the sample length in world space in units + uniform float cOffsetScale, // [0, 1] The distance of the first sample. samples are the + // placed in [cOffsetScale * cSampleLengthScreenSpace, cSampleLengthScreenSpace] + uniform float cDefaultAccessibility, // the default value used in the lerp() expression for invalid samples [0, 1] + uniform float cEdgeHighlight // multiplier for edge highlighting in [1, 2] 1 is full highlighting 2 is off +) +{ + const int nSampleNum = 32; // number of samples + + // compute the distance between the clipping planes to convert [0, 1] depth to world space units + const float clipDepth = farClipDistance - nearClipDistance; + + // get the depth of the current pixel and convert into world space unit [0, inf] + float fragmentWorldDepth = tex2D(sSceneDepthSampler, fragmentTC).w * clipDepth; + + // get rotation vector, rotation is tiled every 4 screen pixels + float2 rotationTC = fragmentTC * cViewportSize.xy / 4; + float3 rotationVector = 2 * tex2D(sRotSampler4x4, rotationTC).xyz - 1; // [-1, 1]x[-1. 1]x[-1. 1] + + float rUV = 0; // radius of influence in screen space + float r = 0; // radius of influence in world space + if (cSampleInScreenspace == 1) + { + rUV = cSampleLengthScreenSpace; + r = tan(rUV * cFov) * fragmentWorldDepth; + } + else + { + rUV = atan(cSampleLengthWorldSpace / fragmentWorldDepth) / cFov; // the radius of influence projected into screen space + r = cSampleLengthWorldSpace; + } + + float sampleLength = cOffsetScale; // the offset for the first sample + const float sampleLengthStep = pow((rUV / sampleLength), 1.0f/nSampleNum); + + float accessibility = 0; + // sample the sphere and accumulate accessibility + for (int i = 0; i < (nSampleNum/8); i++) + { + for (int x = -1; x <= 1; x += 2) + for (int y = -1; y <= 1; y += 2) + for (int z = -1; z <= 1; z += 2) + { + //generate offset vector + float3 offset = normalize(float3(x, y, z)) * sampleLength; + + // update sample length + sampleLength *= sampleLengthStep; + + // reflect offset vector by random rotation sample (i.e. rotating it) + float3 rotatedOffset = reflect(offset, rotationVector); + + float2 sampleTC = fragmentTC + rotatedOffset.xy * rUV; + + // read scene depth at sampling point and convert into world space units (m or whatever) + float sampleWorldDepth = tex2D(sSceneDepthSampler, sampleTC).w * clipDepth; + + // check if depths of both pixels are close enough and sampling point should affect our center pixel + float fRangeIsInvalid = saturate((fragmentWorldDepth - sampleWorldDepth) / r); + + // accumulate accessibility, use default value of 0.5 if right computations are not possible + accessibility += lerp(sampleWorldDepth > (fragmentWorldDepth + rotatedOffset.z * r), cDefaultAccessibility, fRangeIsInvalid); + } + } + + // get average value + accessibility /= nSampleNum; + + // normalize, remove edge highlighting + accessibility *= cEdgeHighlight; + + // amplify and saturate if necessary + oColor0 = float4(accessibility.xxx, 1); +} diff --git a/res/dist/media/materials/scripts/SSAO/Crytek.material b/res/dist/media/materials/scripts/SSAO/Crytek.material new file mode 100644 index 00000000000..0e418b85db9 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/Crytek.material @@ -0,0 +1,57 @@ +fragment_program SSAO/Crytek_fp_hlsl hlsl +{ + source Crytek.cg + entry_point Crytek_fp + target ps_3_0 +} + +fragment_program SSAO/Crytek_fp_cg cg +{ + source Crytek.cg + entry_point Crytek_fp + profiles ps_3_0 arbfp1 +} + +fragment_program SSAO/Crytek_fp unified +{ + delegate SSAO/Crytek_fp_hlsl + delegate SSAO/Crytek_fp_cg +} + +material SSAO/Crytek +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/Crytek_fp + { + param_named_auto cViewportSize viewport_size + param_named_auto farClipDistance far_clip_distance + param_named_auto nearClipDistance near_clip_distance + param_named_auto cFov fov + } + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + + texture_unit + { + // texture regularSphere4.png + texture regularSphereJittered4.png + // texture regularSphereOctant4.png + // texture regularSphereJitteredOctant4.png + // texture rand4x4.png + tex_address_mode wrap + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/GBuffer.cg b/res/dist/media/materials/scripts/SSAO/GBuffer.cg new file mode 100644 index 00000000000..d82a419a844 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/GBuffer.cg @@ -0,0 +1,40 @@ +// courtesy of the ogre wiki and the defered shading sample +// http://www.ogre3d.org/wiki/index.php/Deferred_Shading +//------------------------------------------------------------------------------ + +void GBuffer_vp( + float4 iPosition : POSITION, + float3 iNormal : NORMAL, + + out float4 oPosition : POSITION, + out float3 oViewPos : TEXCOORD0, + out float3 oNormal : TEXCOORD1, + + uniform float4x4 cWorldViewProj, + uniform float4x4 cWorldView + ) +{ + oPosition = mul(cWorldViewProj, iPosition); // transform the vertex position to the projection space + oViewPos = mul(cWorldView, iPosition).xyz; // transform the vertex position to the view space + oNormal = mul(cWorldView, float4(iNormal,0)).xyz; // transform the vertex normal to view space +} + +void GBuffer_fp( + float3 iViewPos : TEXCOORD0, + float3 iNormal : TEXCOORD1, + + out float4 oColor0 : COLOR0, // rgb color + out float4 oNormalDepth : COLOR1, // normal + linear depth [0, 1] + out float4 oViewPos : COLOR2, // view space position + + uniform float cNearClipDistance, + uniform float cFarClipDistance // !!! might be 0 for infinite view projection. + ) +{ + + oColor0 = float4(1, 1, 1, 1); //...and a least little touch of the titanium white... + float clipDistance = cFarClipDistance - cNearClipDistance; + oNormalDepth = float4(normalize(iNormal).xyz, (length(iViewPos) - cNearClipDistance) / clipDistance); + oViewPos = float4(iViewPos, 0); +} + diff --git a/res/dist/media/materials/scripts/SSAO/GBuffer.material b/res/dist/media/materials/scripts/SSAO/GBuffer.material new file mode 100644 index 00000000000..53ebc5f8f7a --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/GBuffer.material @@ -0,0 +1,61 @@ +// Gbuffer Material + +vertex_program SSAO/GBuffer_vp_hlsl hlsl +{ + source GBuffer.cg + entry_point GBuffer_vp + target vs_3_0 +} + +fragment_program SSAO/GBuffer_fp_hlsl hlsl +{ + source GBuffer.cg + entry_point GBuffer_fp + target ps_3_0 +} + +vertex_program SSAO/GBuffer_vp_cg cg +{ + source GBuffer.cg + entry_point GBuffer_vp + profiles vs_2_x arbvp1 +} + +fragment_program SSAO/GBuffer_fp_cg cg +{ + source GBuffer.cg + entry_point GBuffer_fp + profiles ps_3_0 arbfp1 +} + +vertex_program SSAO/GBuffer_vp unified +{ + delegate SSAO/GBuffer_vp_hlsl + delegate SSAO/GBuffer_vp_cg +} +fragment_program SSAO/GBuffer_fp unified +{ + delegate SSAO/GBuffer_fp_hlsl + delegate SSAO/GBuffer_fp_cg +} + +material SSAO/GBuffer +{ + technique + { + pass + { + vertex_program_ref SSAO/GBuffer_vp + { + param_named_auto cWorldViewProj worldviewproj_matrix + param_named_auto cWorldView worldview_matrix + } + + fragment_program_ref SSAO/GBuffer_fp + { + param_named_auto cNearClipDistance near_clip_distance + param_named_auto cFarClipDistance far_clip_distance + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/HemisphereMC.cg b/res/dist/media/materials/scripts/SSAO/HemisphereMC.cg new file mode 100644 index 00000000000..6f1ac64140b --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/HemisphereMC.cg @@ -0,0 +1,86 @@ +void HemisphereMC_fp +( + in const float2 uv : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sMRT1 : register(s0), // fragment normals + uniform sampler sMRT2 : register(s1), // view space position, remember that we are looking down the negative Z axis!!! + uniform sampler sRand : register(s2), // MxN random texture, M sets of N precomputed low-discrepancy samples + + uniform const float4 cViewportSize, // (viewport_width, viewport_height, inverse_viewport_width, inverse_viewport_height) + uniform const float cFov, // vertical field of view in radians + uniform const float cSampleInScreenspace, // whether to sample in screen or world space + uniform const float cSampleLengthScreenSpace, // The sample length in screen space [0, 1] + uniform const float cSampleLengthWorldSpace, // the sample length in world space in units + uniform const float cSampleLengthExponent // The exponent of the sample length +) +{ + const int interleaved = 4; + const int m = 8; + const int n = 4; + const int numSamples = m * n; + const float2 interleaveOffset = uv * cViewportSize.xy / interleaved; + const float3 fragmentPosition = tex2D(sMRT2, uv).xyz; // the current fragment in view space + const float3 fragmentNormal = tex2D(sMRT1, uv).xyz; // the fragment normal + float rUV = 0; // radius of influence in screen space + float r = 0; // radius of influence in world space + + if (cSampleInScreenspace == 1) + { + rUV = cSampleLengthScreenSpace; + r = tan(rUV * cFov) * -fragmentPosition.z; + } + else + { + rUV = atan(cSampleLengthWorldSpace / -fragmentPosition.z) / cFov; // the radius of influence projected into screen space + r = cSampleLengthWorldSpace; + } + + if (rUV < (cViewportSize.z)) // abort if the projected radius of influence is smaller than 1 fragment + { + oColor0 = 1; + return; + } + + + float accessibility = 0; // accessibility of the fragment + + const float3 viewVector = float3(0, 0, 1); // the constant view vector in view space + + // the reflection vector to align the hemisphere with the fragment normal + // somehow the x component must be flipped...??? + const float3 reflector = normalize(fragmentNormal + viewVector) * float3(-1, 1, 1); + + float count = 0; + float sampleLength; + + for (float i = 0.0f; i < m; i++) + for (float j = 0.0f; j < n; j++) + { + count ++; + + const float2 randomTC = interleaveOffset + float2(i/(interleaved * m), j/(interleaved * n)); + float3 randomVector = (tex2D(sRand, randomTC) * 2 - 1); // unpack to [-1, 1]x[-1, 1]x[1, 1] + + sampleLength = pow(count/(float)numSamples, cSampleLengthExponent); + + const float3 sampleVector = reflect(randomVector, reflector) * sampleLength; + + const float2 sampleTC = uv + sampleVector.xy * rUV; + + const float3 samplePosition = tex2D(sMRT2, sampleTC); + + if (samplePosition.z < (fragmentPosition.z - sampleVector.z * r)) // thin air + accessibility++; + else // solid geometry + accessibility += length(fragmentPosition - samplePosition) > r; // out of reach, i.e. false occluder + } + + accessibility /= numSamples; + oColor0 = float4(accessibility.xxx, 1); + + float3 direction = 0; + direction += reflect(float3(0, 0, -1), reflector); + direction = normalize(direction); +} diff --git a/res/dist/media/materials/scripts/SSAO/HemisphereMC.material b/res/dist/media/materials/scripts/SSAO/HemisphereMC.material new file mode 100644 index 00000000000..525d41ba3fb --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/HemisphereMC.material @@ -0,0 +1,60 @@ +fragment_program SSAO/HemisphereMC_fp_hlsl hlsl +{ + source HemisphereMC.cg + entry_point HemisphereMC_fp + target ps_3_0 +} + +fragment_program SSAO/HemisphereMC_fp_cg cg +{ + source HemisphereMC.cg + entry_point HemisphereMC_fp + profiles ps_3_0 arbfp1 +} + +fragment_program SSAO/HemisphereMC_fp unified +{ + delegate SSAO/HemisphereMC_fp_hlsl + delegate SSAO/HemisphereMC_fp_cg +} + +// Monte Carlo Integration of the hemisphere definded by the fragment normal +// lossely based on Ritschel et al. SSDO. +material SSAO/HemisphereMC +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/HemisphereMC_fp + { + param_named_auto cViewportSize viewport_size + param_named_auto cFov fov + } + + texture_unit // normals + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + + texture_unit // view space position + { + content_type compositor SSAO/GBuffer mrt 2 + tex_address_mode clamp + filtering none + } + + texture_unit + { + texture importance4InterleavedSphereHemisphere8x4.png + tex_address_mode wrap + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/HorizonBased.cg b/res/dist/media/materials/scripts/SSAO/HorizonBased.cg new file mode 100644 index 00000000000..35a5d437294 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/HorizonBased.cg @@ -0,0 +1,95 @@ +void HorizonBased_fp +( + in float2 uv : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sMRT1 : register(s0), // fragment normal + uniform sampler sMRT2 : register(s1), // view space position + uniform sampler sRand : register(s2), // (cos(a), sin(a), jitter + + uniform float4 cViewportSize, // (viewport_width, viewport_height, inverse_viewport_width, inverse_viewport_height) + uniform float cFov, // vertical field of view in radians + uniform float cSampleInScreenspace, // whether to sample in screen or world space + uniform float cSampleLengthScreenSpace, // The sample length in screen space [0, 1] + uniform float cSampleLengthWorldSpace, // the sample length in world space in units + uniform float cAngleBias // angle bias to avoid shadows in low tessellated curvatures [0, pi/2] +) +{ + const float pi = 3.1415926535897932384626433832795028841971693993751; + + const float numSteps = 7; // number of samples/steps along a direction + const float numDirections = 4; // number of sampling directions in uv space + + float3 p = tex2D(sMRT2, uv).xyz; // the current fragment in view space + float3 pointNormal = tex2D(sMRT1, uv).xyz; // the fragment normal + + float Ruv = 0; // radius of influence in screen space + float R = 0; // radius of influence in world space + if (cSampleInScreenspace == 1) + { + Ruv = cSampleLengthScreenSpace; + R = tan(Ruv * cFov) * -p.z; + } + else + { + Ruv = atan(cSampleLengthWorldSpace / -p.z) / cFov; // the radius of influence projected into screen space + R = cSampleLengthWorldSpace; + } + + // if the radius of influence is smaller than one fragment we exit early, + // since all samples would hit the current fragment. + if (Ruv < (1 / cViewportSize.x)) + { + oColor0 = float4(1, 1, 1, 1); + return; + } + + float occlusion = 0; // occlusion of the fragment + float2x2 directionMatrix; // the matrix to create the sample directions + // the compiler should evaluate the directions at compile time + directionMatrix._m00 = cos((2 * pi) / numDirections); + directionMatrix._m01 = sin((2 * pi) / numDirections); + directionMatrix._m10 = - sin((2 * pi) / numDirections); + directionMatrix._m11 = cos((2 * pi) / numDirections); + float2 deltaUV = float2(1, 0) * (Ruv / (numSteps + 1)); // The step vector in view space. scale it to the step size + // we don't want to sample to the perimeter of R since those samples would be + // omitted by the distance attenuation (W(R) = 0 by definition) + // Therefore we add a extra step and don't use the last sample. + + float3 randomValues = tex2D(sRand, (uv * cViewportSize.xy) / 4); //4px tiles + float2x2 rotationMatrix; + rotationMatrix._m00 = (randomValues.x - 0.5) * 2; + rotationMatrix._m01 = (randomValues.y - 0.5) * 2; + rotationMatrix._m10 = - rotationMatrix._m01; + rotationMatrix._m11 = rotationMatrix._m00; + float jitter = randomValues.z; + + for (int i = 0; i < numDirections; i++) + { + deltaUV = mul(deltaUV, directionMatrix); // rotate the deltaUV vector by 1/numDirections + float2 sampleDirection = mul(deltaUV, rotationMatrix); // now rotate this vector with the random rotation + + float oldAngle = cAngleBias; + + for (int j = 1; j <= numSteps; j++) // sample along a direction, needs to start at one, for the sake of the next line + { + float2 sampleUV = uv + ((jitter + j) * sampleDirection); // jitter the step a little bit + + float3 sample = tex2D(sMRT2, sampleUV); // the sample in view space + float3 sampleVector = (sample - p); + float gamma = (pi / 2) - acos(dot(pointNormal, normalize(sampleVector))); //the angle between the fragment tangent and the sample + + if (gamma > oldAngle) + { + float attenuation = saturate(1 - (pow((length(sampleVector) / R), 2))); + occlusion += attenuation * (sin(gamma) - sin(oldAngle)); + oldAngle = gamma; + } + } + } + + // ??? should step samples that fall under the horizontal be considered in the following line??? + occlusion /= (numDirections * numSteps); + oColor0 = 1 - float4(occlusion.xxx, 1) * 2 * pi; +} diff --git a/res/dist/media/materials/scripts/SSAO/HorizonBased.material b/res/dist/media/materials/scripts/SSAO/HorizonBased.material new file mode 100644 index 00000000000..f7c0cd15693 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/HorizonBased.material @@ -0,0 +1,58 @@ +fragment_program SSAO/HorizonBased_fp_hlsl hlsl +{ + source HorizonBased.cg + entry_point HorizonBased_fp + target ps_3_0 +} + +fragment_program SSAO/HorizonBased_fp_cg cg +{ + source HorizonBased.cg + entry_point HorizonBased_fp + profiles ps_3_0 arbfp1 +} + +fragment_program SSAO/HorizonBased_fp unified +{ + delegate SSAO/HorizonBased_fp_hlsl + delegate SSAO/HorizonBased_fp_cg +} + +material SSAO/HorizonBased +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/HorizonBased_fp + { + param_named_auto cViewportSize viewport_size + param_named_auto cFov fov + } + + texture_unit // fragment normal + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + + texture_unit // view position + { + content_type compositor SSAO/GBuffer mrt 2 + tex_address_mode clamp + filtering none + } + + texture_unit + { + texture randCosSinJitter4x4.png + tex_address_mode wrap + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/SSAO.compositor b/res/dist/media/materials/scripts/SSAO/SSAO.compositor new file mode 100644 index 00000000000..46d02c30944 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/SSAO.compositor @@ -0,0 +1,224 @@ +compositor SSAO/GBuffer +{ + technique + { + // GBuffer enconding: -------------------------------------------------- + // mrt0: rgba --> unused in this sample (plain white, (1, 1, 1, 1)) + // mrt1: xyz --> normals, w --> normalized linear depth [0, 1] + // mrt2: xyz --> position in view space + // + // use a better packing of variables in the mrt to (possibly) increase + // performance! + // --------------------------------------------------------------------- + + texture mrt target_width target_height PF_FLOAT32_RGBA PF_FLOAT32_RGBA PF_FLOAT32_RGBA chain_scope + texture occlusion target_width target_height PF_FLOAT32_RGBA chain_scope + + target mrt + { + input none + shadows off + + pass clear + { + buffers colour depth stencil + depth_value 1.0 + } + + pass render_scene {} + } + } +} + +compositor SSAO/Volumetric // Szirmay-Kalos et al 2010 +{ + technique + { + texture_ref occlusion SSAO/GBuffer occlusion + + target occlusion + { + input none + + pass render_quad + { + material SSAO/Volumetric + } + } + } +} + + +compositor SSAO/HemisphereMC // Ritschel et al. inspired hemisphere mc integration +{ + technique + { + texture_ref occlusion SSAO/GBuffer occlusion + + target occlusion + { + input none + + pass render_quad + { + material SSAO/HemisphereMC + } + } + } +} + +compositor SSAO/HorizonBased // Bavoil and Sainz in ShaderX7 +{ + technique + { + texture_ref occlusion SSAO/GBuffer occlusion + + target occlusion + { + input none + + pass render_quad + { + material SSAO/HorizonBased + } + } + } +} + + +compositor SSAO/Crytek // Crytek style ssao as found in shaderX7 +{ + technique + { + texture_ref occlusion SSAO/GBuffer occlusion + + target occlusion + { + input none + + pass render_quad + { + material SSAO/Crytek + } + } + } +} + + +compositor SSAO/CreaseShading // Megan Fox's crease shading http://www.shalinor.com/research.html +{ + technique + { + texture_ref occlusion SSAO/GBuffer occlusion + + target occlusion + { + input none + + pass render_quad + { + material SSAO/CreaseShading + } + } + } +} + +compositor SSAO/UnsharpMask //Unsharp mask the depth buffer [LCD2006] +{ + technique + { + texture blurred target_width target_height PF_FLOAT32_RGBA + texture_ref occlusion SSAO/GBuffer occlusion + + target blurred + { + input none + + pass render_quad + { + material SSAO/UnsharpMask/GaussianBlurX + } + } + + target blurred + { + input none + + pass render_quad + { + material SSAO/UnsharpMask/GaussianBlurY + input 0 blurred + } + } + + target occlusion + { + input none + pass clear {} + + pass render_quad + { + material SSAO/UnsharpMask + input 0 blurred + } + } + } +} + +compositor SSAO/ShowNormals +{ + technique + { + texture_ref occlusion SSAO/GBuffer occlusion + + target occlusion + { + input none + + pass render_quad + { + // Renders a fullscreen quad with a material + material SSAO/ShowNormals + } + } + } +} + +compositor SSAO/ShowDepth +{ + technique + { + texture_ref occlusion SSAO/GBuffer occlusion + + target occlusion + { + input none + + pass render_quad + { + // Renders a fullscreen quad with a material + material SSAO/ShowDepth + } + } + } +} + +compositor SSAO/ShowViewPos +{ + technique + { + texture_ref occlusion SSAO/GBuffer occlusion + + target occlusion + { + input none + + pass render_quad + { + // Renders a fullscreen quad with a material + material SSAO/ShowViewPos + } + } + } +} + diff --git a/res/dist/media/materials/scripts/SSAO/SSAOPost.cg b/res/dist/media/materials/scripts/SSAO/SSAOPost.cg new file mode 100644 index 00000000000..063b7a2a9ca --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/SSAOPost.cg @@ -0,0 +1,153 @@ +void noFilter_fp ( + in float2 uv : TEXCOORD0, + out float4 oColor0 : COLOR0, + + uniform sampler sOcclusion : register(s0) +) +{ + oColor0 = float4(tex2D(sOcclusion, uv).xyz, 1); +} + + +// a very simple 4x4 box filter +// the kernel has the following form +// o o o o +// o o o o +// o o x o +// o o o o +// where x marks the fragment position and the o marks a sampling point +void boxFilter_fp +( + in float2 screenTC : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sOcclusion : register(s0), + uniform float4 screenSize, + uniform float farClipDistance +) +{ + float color = 0; + for (int x = -2; x < 2; x++) + for (int y = -2; y < 2; y++) + { + color += tex2D(sOcclusion, float2(screenTC.x + x * screenSize.z, screenTC.y + y * screenSize.w)).x; + } + color /= 16; + + oColor0 = float4(color.xxx, 1); +} + + +// a very simple and slightly dumb depth aware 4x4 box filter +// the kernel has the following form +// o o o o +// o o o o +// o o x o +// o o o o +// where x marks the fragment position and the o marks a sampling point +void smartBoxFilter_fp +( + in float2 screenTC : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sMrt1 : register(s0), // normals + depth + uniform sampler sOcclusion : register(s1), + uniform float4 screenSize, + uniform float farClipDistance +) +{ + float fragmentDepth = tex2D(sMrt1, screenTC).x; + + float color = 0; + float weight = 0; + for (int x = -2; x < 2; x++) + for (int y = -2; y < 2; y++) + { + float sampleDepth = tex2D(sMrt1, float2(screenTC.x + x * screenSize.z, screenTC.y + y * screenSize.w)).x; + float dist = abs(fragmentDepth - sampleDepth) * farClipDistance + 0.5; + float sampleWeight = 1 / (pow(dist, 1) + 1); + color += sampleWeight * tex2D(sOcclusion, float2(screenTC.x + x * screenSize.z, screenTC.y + y * screenSize.w)).x; + weight += sampleWeight; + } + color /= weight; + + oColor0 = float4(color.xxx, 1); +// oColor0 = float4(tex2D(sOcclusion, screenTC).www, 1); +} + + +// cross bilateral filter +// gaussian blur with photometric weighting +// note: encode the viewspace z component in the accessibility texture to reduce +// the texture fetch count +void crossBilateralFilterX_fp +( + in float2 uv : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sAccessibility : register(s0), + uniform sampler sMRT2 : register(s1), // the view space position, xyz + + uniform float stepX, // inverse viewport width + uniform float cPhotometricExponent +) +{ + const int kernelWidth = 13; + float sigma = (kernelWidth - 1) / 6; // make the kernel span 6 sigma + + float fragmentDepth = tex2D(sMRT2, uv).z; + + float weights = 0; + float blurred = 0; + + for (float i = -(kernelWidth - 1) / 2; i < (kernelWidth - 1) / 2; i++) + { + float geometricWeight = exp(-pow(i, 2) / (2 * pow(sigma, 2))); + float sampleDepth = tex2D(sMRT2, float2(uv.x - i * stepX, uv.y)).z; + float photometricWeight = 1 / pow((1 + abs(fragmentDepth - sampleDepth)), cPhotometricExponent); + + weights += (geometricWeight * photometricWeight); + blurred += tex2D(sAccessibility, float2(uv.x - i * stepX, uv.y)).r * geometricWeight * photometricWeight; + } + + blurred /= weights; + oColor0 = float4(blurred.xxx, 1); +} + +void crossBilateralFilterY_fp +( + in float2 uv : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sAccessibility : register(s0), + uniform sampler sMRT2 : register(s1), // the view space position, xyz + + uniform float stepY, // inverse viewport width + uniform float cPhotometricExponent +) +{ + const int kernelWidth = 13; + float sigma = (kernelWidth - 1) / 6; // make the kernel span 6 sigma + + float fragmentDepth = tex2D(sMRT2, uv).z; + + float weights = 0; + float blurred = 0; + + for (float i = -(kernelWidth - 1) / 2; i < (kernelWidth - 1) / 2; i++) + { + float geometricWeight = exp(-pow(i, 2) / (2 * pow(sigma, 2))); + float sampleDepth = tex2D(sMRT2, float2(uv.x, uv.y - i * stepY)).z; + float photometricWeight = 1 / pow((1 + abs(fragmentDepth - sampleDepth)), cPhotometricExponent); + + weights += (geometricWeight * photometricWeight); + blurred += tex2D(sAccessibility, float2(uv.x, uv.y - i * stepY)).r * geometricWeight * photometricWeight; + } + + blurred /= weights; + oColor0 = float4(blurred.xxx, 1); +} diff --git a/res/dist/media/materials/scripts/SSAO/SSAOPost.compositor b/res/dist/media/materials/scripts/SSAO/SSAOPost.compositor new file mode 100644 index 00000000000..7eeaa297cea --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/SSAOPost.compositor @@ -0,0 +1,77 @@ +compositor SSAO/Post/NoFilter +{ + technique + { + target_output + { + input none + + pass render_quad + { + material SSAO/Post/NoFilter + } + } + } +} + +compositor SSAO/Post/BoxFilter +{ + technique + { + target_output + { + input none + + pass render_quad + { + material SSAO/Post/BoxFilter + } + } + } +} + +compositor SSAO/Post/SmartBoxFilter +{ + technique + { + target_output + { + input none + + pass render_quad + { + material SSAO/Post/SmartBoxFilter + } + } + } +} + + +compositor SSAO/Post/CrossBilateralFilter +{ + technique + { + texture accessibility target_width target_height PF_R8G8B8A8 + + target accessibility + { + input none + + pass render_quad + { + material SSAO/HorizonBased/CrossBilateralFilter/X + } + } + + target_output + { + input none + + pass render_quad + { + material SSAO/HorizonBased/CrossBilateralFilter/Y + input 0 accessibility + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/SSAOPost.material b/res/dist/media/materials/scripts/SSAO/SSAOPost.material new file mode 100644 index 00000000000..433f97648d4 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/SSAOPost.material @@ -0,0 +1,239 @@ +fragment_program SSAO/Post/NoFilter_fp_hlsl hlsl +{ + source SSAOPost.cg + entry_point noFilter_fp + target ps_3_0 +} + +fragment_program SSAO/Post/BoxFilter_fp_hlsl hlsl +{ + source SSAOPost.cg + entry_point boxFilter_fp + target ps_3_0 +} + +fragment_program SSAO/Post/SmartBoxFilter_fp_hlsl hlsl +{ + source SSAOPost.cg + entry_point smartBoxFilter_fp + target ps_3_0 +} + +fragment_program SSAO/HorizonBased/CrossBilateralFilter/X_fp_hlsl hlsl +{ + source SSAOPost.cg + entry_point crossBilateralFilterX_fp + target ps_3_0 +} + +fragment_program SSAO/HorizonBased/CrossBilateralFilter/Y_fp_hlsl hlsl +{ + source SSAOPost.cg + entry_point crossBilateralFilterY_fp + target ps_3_0 +} + +fragment_program SSAO/Post/NoFilter_fp_cg cg +{ + source SSAOPost.cg + entry_point noFilter_fp + profiles ps_3_0 arbfp1 +} + +fragment_program SSAO/Post/BoxFilter_fp_cg cg +{ + source SSAOPost.cg + entry_point boxFilter_fp + profiles ps_3_0 arbfp1 +} + +fragment_program SSAO/Post/SmartBoxFilter_fp_cg cg +{ + source SSAOPost.cg + entry_point smartBoxFilter_fp + profiles ps_3_0 arbfp1 +} + +fragment_program SSAO/HorizonBased/CrossBilateralFilter/X_fp_cg cg +{ + source SSAOPost.cg + entry_point crossBilateralFilterX_fp + profiles ps_3_0 arbfp1 +} + +fragment_program SSAO/HorizonBased/CrossBilateralFilter/Y_fp_cg cg +{ + source SSAOPost.cg + entry_point crossBilateralFilterY_fp + profiles ps_3_0 arbfp1 +} + +fragment_program SSAO/Post/NoFilter_fp unified +{ + delegate SSAO/Post/NoFilter_fp_hlsl + delegate SSAO/Post/NoFilter_fp_cg +} + +fragment_program SSAO/Post/BoxFilter_fp unified +{ + delegate SSAO/Post/BoxFilter_fp_hlsl + delegate SSAO/Post/BoxFilter_fp_cg +} + +fragment_program SSAO/Post/SmartBoxFilter_fp unified +{ + delegate SSAO/Post/SmartBoxFilter_fp_hlsl + delegate SSAO/Post/SmartBoxFilter_fp_cg +} + +fragment_program SSAO/HorizonBased/CrossBilateralFilter/X_fp unified +{ + delegate SSAO/HorizonBased/CrossBilateralFilter/X_fp_hlsl + delegate SSAO/HorizonBased/CrossBilateralFilter/X_fp_cg +} + +fragment_program SSAO/HorizonBased/CrossBilateralFilter/Y_fp unified +{ + delegate SSAO/HorizonBased/CrossBilateralFilter/Y_fp_hlsl + delegate SSAO/HorizonBased/CrossBilateralFilter/Y_fp_cg +} + +material SSAO/Post/NoFilter +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/Post/NoFilter_fp {} + + texture_unit + { + content_type compositor SSAO/GBuffer occlusion + tex_address_mode clamp + filtering none + } + } + } +} + +material SSAO/Post/BoxFilter +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/Post/BoxFilter_fp + { + param_named_auto screenSize viewport_size + } + + texture_unit + { + content_type compositor SSAO/GBuffer occlusion + tex_address_mode clamp + filtering none + } + } + } +} + +material SSAO/Post/SmartBoxFilter +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/Post/SmartBoxFilter_fp + { + param_named_auto screenSize viewport_size + param_named_auto farClipDistance far_clip_distance + } + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + + texture_unit + { + content_type compositor SSAO/GBuffer occlusion + tex_address_mode clamp + filtering none + } + } + } +} + +material SSAO/HorizonBased/CrossBilateralFilter/X +{ + technique + { + pass // two pass in x and y direction + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/HorizonBased/CrossBilateralFilter/X_fp + { + param_named_auto stepX inverse_viewport_width + } + + texture_unit // the accessability texture + { + content_type compositor SSAO/GBuffer occlusion + tex_address_mode clamp + filtering none + } + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 2 + tex_address_mode clamp + filtering none + } + } + } +} + +material SSAO/HorizonBased/CrossBilateralFilter/Y +{ + technique + { + pass // two pass in x and y direction + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/HorizonBased/CrossBilateralFilter/Y_fp + { + param_named_auto stepY inverse_viewport_height + } + + texture_unit // the accessability texture, injected by the compositor + { + tex_address_mode clamp + filtering none + } + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 2 + tex_address_mode clamp + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/ShowDepth.cg b/res/dist/media/materials/scripts/SSAO/ShowDepth.cg new file mode 100644 index 00000000000..b44bdab29be --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/ShowDepth.cg @@ -0,0 +1,13 @@ +void ShowDepth_fp +( + in float2 iTexCoord: TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler mrt1: register(s0), + uniform sampler tex : register(s1) +) +{ + float depth = tex2D(mrt1, iTexCoord).w; + oColor0 = float4(tex2D(tex, float2(depth*20, 0)).rgb, 1); +} diff --git a/res/dist/media/materials/scripts/SSAO/ShowDepth.material b/res/dist/media/materials/scripts/SSAO/ShowDepth.material new file mode 100644 index 00000000000..153b5a9463d --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/ShowDepth.material @@ -0,0 +1,47 @@ +fragment_program SSAO/ShowDepth_fp_hlsl hlsl +{ + source ShowDepth.cg + entry_point ShowDepth_fp + target ps_3_0 +} + +fragment_program SSAO/ShowDepth_fp_cg cg +{ + source ShowDepth.cg + entry_point ShowDepth_fp + profiles ps_2_x arbfp1 +} + +fragment_program SSAO/ShowDepth_fp unified +{ + delegate SSAO/ShowDepth_fp_hlsl + delegate SSAO/ShowDepth_fp_cg +} + +material SSAO/ShowDepth +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/ShowDepth_fp {} + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + + texture_unit + { + texture gray256.png + tex_address_mode wrap + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/ShowNormals.cg b/res/dist/media/materials/scripts/SSAO/ShowNormals.cg new file mode 100644 index 00000000000..39b4682145b --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/ShowNormals.cg @@ -0,0 +1,11 @@ +void ShowNormals_fp +( + in float2 iTexCoord : TEXCOORD0, + + out float4 oColor0: COLOR0, + + uniform sampler mrt1: register(s0) +) +{ + oColor0 = float4(tex2D(mrt1, iTexCoord).xyz / 2 + 0.5, 1); +} diff --git a/res/dist/media/materials/scripts/SSAO/ShowNormals.material b/res/dist/media/materials/scripts/SSAO/ShowNormals.material new file mode 100644 index 00000000000..0037d061672 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/ShowNormals.material @@ -0,0 +1,40 @@ +fragment_program SSAO/ShowNormals_fp_hlsl hlsl +{ + source ShowNormals.cg + entry_point ShowNormals_fp + target ps_2_0 +} + +fragment_program SSAO/ShowNormals_fp_cg cg +{ + source ShowNormals.cg + entry_point ShowNormals_fp + profiles ps_2_0 arbfp1 +} + +fragment_program SSAO/ShowNormals_fp unified +{ + delegate SSAO/ShowNormals_fp_hlsl + delegate SSAO/ShowNormals_fp_cg +} + +material SSAO/ShowNormals +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/ShowNormals_fp {} + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/ShowViewPos.cg b/res/dist/media/materials/scripts/SSAO/ShowViewPos.cg new file mode 100644 index 00000000000..69fcdeac5bd --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/ShowViewPos.cg @@ -0,0 +1,11 @@ +void ShowViewPos_fp +( + in float2 iTexCoord : TEXCOORD0, + + out float4 oColor0: COLOR0, + + uniform sampler mrt2: register(s0) +) +{ + oColor0 = float4(tex2D(mrt2, iTexCoord).xyz * float3(0.1, 0.1, -0.01), 1); +} diff --git a/res/dist/media/materials/scripts/SSAO/ShowViewPos.material b/res/dist/media/materials/scripts/SSAO/ShowViewPos.material new file mode 100644 index 00000000000..6711ec0fae4 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/ShowViewPos.material @@ -0,0 +1,40 @@ +fragment_program SSAO/ShowViewPos_fp_hlsl hlsl +{ + source ShowViewPos.cg + entry_point ShowViewPos_fp + target ps_2_0 +} + +fragment_program SSAO/ShowViewPos_fp_cg cg +{ + source ShowViewPos.cg + entry_point ShowViewPos_fp + profiles ps_2_0 arbfp1 +} + +fragment_program SSAO/ShowViewPos_fp unified +{ + delegate SSAO/ShowViewPos_fp_hlsl + delegate SSAO/ShowViewPos_fp_cg +} + +material SSAO/ShowViewPos +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/ShowViewPos_fp {} + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/UnsharpMask.cg b/res/dist/media/materials/scripts/SSAO/UnsharpMask.cg new file mode 100644 index 00000000000..bea9536fc14 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/UnsharpMask.cg @@ -0,0 +1,79 @@ +void UnsharpMask_fp +( + in float2 iTexCoord : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler blurred: register(s0), + uniform sampler mrt0: register(s1), + uniform sampler mrt1: register(s2), + uniform float cLambda +) +{ + float spacialImportance = tex2D(blurred, iTexCoord).w - tex2D(mrt1, iTexCoord).w; + float4 color = tex2D(mrt0, iTexCoord); + if (spacialImportance < 0) // darkening only + { + oColor0 = float4(color.rgb + (cLambda * spacialImportance), 1); + } else + { + oColor0 = color; + } +} + +void GaussianBlurX_fp +( + in float2 uv : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler mrt1 : register(s0), + uniform float stepX, + uniform const float cKernelWidthBias +) +{ + const int kernelWidth = 19; + float sigma = (kernelWidth - 1) / 6; // make the kernel span 6 sigma + + float weights = 0; + float blurredDepth = 0; + + for (float i = -(kernelWidth - 1) / 2; i < (kernelWidth - 1) / 2; i++) + { + float geometricWeight = exp(-pow(i, 2) / (2 * pow(sigma, 2))); + weights += geometricWeight; + blurredDepth += tex2D(mrt1, float2(uv.x - i * stepX * cKernelWidthBias, uv.y)).w * geometricWeight; + } + + blurredDepth /= weights; + oColor0 = float4(tex2D(mrt1, uv).xyz, blurredDepth); +} + +void GaussianBlurY_fp +( + in float2 uv : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler mrt1 : register(s0), + uniform const float stepY, + uniform const float cKernelWidthBias +) +{ + const int kernelWidth = 19; + float sigma = (kernelWidth - 1) / 6; // make the kernel span 6 sigma + + float weights = 0; + float blurredDepth = 0; + + for (float i = -(kernelWidth - 1) / 2; i < (kernelWidth - 1) / 2; i++) + { + float geometricWeight = exp(-pow(i, 2) / (2 * pow(sigma, 2))); + weights += geometricWeight; + blurredDepth += tex2D(mrt1, float2(uv.x, uv.y - i * stepY * cKernelWidthBias)).w * geometricWeight; + } + + blurredDepth /= weights; + oColor0 = float4(tex2D(mrt1, uv).xyz, blurredDepth); +} + diff --git a/res/dist/media/materials/scripts/SSAO/UnsharpMask.material b/res/dist/media/materials/scripts/SSAO/UnsharpMask.material new file mode 100644 index 00000000000..a3bbd42768f --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/UnsharpMask.material @@ -0,0 +1,141 @@ +fragment_program SSAO/UnsharpMask_fp_hlsl hlsl +{ + source UnsharpMask.cg + entry_point UnsharpMask_fp + target ps_3_0 +} + +fragment_program SSAO/UnsharpMask/GaussianBlurX_fp_hlsl hlsl +{ + source UnsharpMask.cg + entry_point GaussianBlurX_fp + target ps_3_0 +} + +fragment_program SSAO/UnsharpMask/GaussianBlurY_fp_hlsl hlsl +{ + source UnsharpMask.cg + entry_point GaussianBlurY_fp + target ps_3_0 +} + +fragment_program SSAO/UnsharpMask_fp_cg cg +{ + source UnsharpMask.cg + entry_point UnsharpMask_fp + profiles ps_2_0 arbfp1 +} + +fragment_program SSAO/UnsharpMask/GaussianBlurX_fp_cg cg +{ + source UnsharpMask.cg + entry_point GaussianBlurX_fp + profiles ps_2_0 arbfp1 +} + +fragment_program SSAO/UnsharpMask/GaussianBlurY_fp_cg cg +{ + source UnsharpMask.cg + entry_point GaussianBlurY_fp + profiles ps_2_0 arbfp1 +} + +fragment_program SSAO/UnsharpMask_fp unified +{ + delegate SSAO/UnsharpMask_fp_hlsl + delegate SSAO/UnsharpMask_fp_cg +} + +fragment_program SSAO/UnsharpMask/GaussianBlurX_fp unified +{ + delegate SSAO/UnsharpMask/GaussianBlurX_fp_hlsl + delegate SSAO/UnsharpMask/GaussianBlurX_fp_cg +} + +fragment_program SSAO/UnsharpMask/GaussianBlurY_fp unified +{ + delegate SSAO/UnsharpMask/GaussianBlurY_fp_hlsl + delegate SSAO/UnsharpMask/GaussianBlurY_fp_cg +} + +material SSAO/UnsharpMask/GaussianBlurX +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/UnsharpMask/GaussianBlurX_fp + { + param_named_auto stepX inverse_viewport_width + } + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + } + } +} + +material SSAO/UnsharpMask/GaussianBlurY +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/UnsharpMask/GaussianBlurY_fp + { + param_named_auto stepY inverse_viewport_height + } + + texture_unit + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + } + } +} + +material SSAO/UnsharpMask +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/UnsharpMask_fp {} + + texture_unit // blurred depth buffer + { + tex_address_mode clamp + filtering none + } + + texture_unit // color component of the GBuffer + { + content_type compositor SSAO/GBuffer mrt 0 + tex_address_mode clamp + filtering none + } + + texture_unit // original depth buffer + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/SSAO/Volumetric.cg b/res/dist/media/materials/scripts/SSAO/Volumetric.cg new file mode 100644 index 00000000000..3b4d6673079 --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/Volumetric.cg @@ -0,0 +1,82 @@ +void Volumetric_fp +( + in const float2 uv : TEXCOORD0, + + out float4 oColor0 : COLOR0, + + uniform sampler sMRT1 : register(s0), // fragment normals + uniform sampler sMRT2 : register(s1), // view space position, remember that we are looking down the negative Z axis!!! + uniform sampler sRand : register(s2), + + uniform const float4 cViewportSize, // (viewport_width, viewport_height, inverse_viewport_width, inverse_viewport_height) + uniform const float cFov, // vertical field of view in radians + uniform const float cSampleInScreenspace, // whether to sample in screen or world space + uniform const float cSampleLengthScreenSpace, // The sample length in screen space [0, 1] + uniform const float cSampleLengthWorldSpace // the sample length in world space in units +) +{ + const int interleaved = 4; + const int m = 8; + const int n = 4; + const int numSamples = m * n; + + const float2 interleaveOffset = uv * cViewportSize.xy / interleaved; + + const float3 fragmentPosition = tex2D(sMRT2, uv).xyz; // the current fragment in view space + const float3 fragmentNormal = tex2D(sMRT1, uv).xyz * float3(1, -1, 1); // the fragment normal + + float rUV = 0; // radius of influence in screen space + float r = 0; // radius of influence in world space + if (cSampleInScreenspace == 1) + { + rUV = cSampleLengthScreenSpace; + r = tan(rUV * cFov) * -fragmentPosition.z; + } + else + { + rUV = atan(cSampleLengthWorldSpace / -fragmentPosition.z) / cFov; // the radius of influence projected into screen space + r = cSampleLengthWorldSpace; + } + + + if (rUV < (cViewportSize.z)) // abort if the projected radius of influence is smaller than 1 fragment + { + oColor0 = 1; + return; + } + + const float r2 = r/2; + const float rUV2 = rUV /2; + + const float3 center = fragmentPosition + fragmentNormal * (r2); + const float2 centerUV = uv + fragmentNormal * (rUV2); + + float F = 0; // unoccluded Volume + float V = 0; // occluded Volume + float invalid = 0; + + for (float i = 0.0f; i < m; i++) + for (float j = 0.0f; j < n; j++) + { + const float2 randomTC = interleaveOffset + float2(i/(interleaved * m), j/(interleaved * n)); + const float2 randomVector = (tex2D(sRand, randomTC) * 2 - 1).xy; // unpack to [-1, 1]^2 + + const float2 sample = randomVector * (r2); + const float2 sampleUV = randomVector * (rUV2); + + const float zEntry = center.z + (r2) * sqrt(1 - sample.x * sample.x - sample.y * sample.y); + const float zExit = center.z - (r2) * sqrt(1 - sample.x * sample.x - sample.y * sample.y); + const float zStar = tex2D(sMRT2, centerUV + sampleUV).z; + + F += zExit - zEntry; + + if (zExit <= zStar && zStar <= zEntry) + V += zStar - zEntry; + else //if (zStar < zExit) + V += zExit - zEntry; + } + + float accessibility = V / F; + oColor0 = float4(accessibility.xxx, 1); + +} diff --git a/res/dist/media/materials/scripts/SSAO/Volumetric.material b/res/dist/media/materials/scripts/SSAO/Volumetric.material new file mode 100644 index 00000000000..a02b20889ba --- /dev/null +++ b/res/dist/media/materials/scripts/SSAO/Volumetric.material @@ -0,0 +1,59 @@ +fragment_program SSAO/Volumetric_fp_hlsl hlsl +{ + source Volumetric.cg + entry_point Volumetric_fp + target ps_3_0 +} + +fragment_program SSAO/Volumetric_fp_cg cg +{ + source Volumetric.cg + entry_point Volumetric_fp + profiles arbfp1 ps_3_0 +} + +fragment_program SSAO/Volumetric_fp unified +{ + delegate SSAO/Volumetric_fp_hlsl + delegate SSAO/Volumetric_fp_cg +} + + +material SSAO/Volumetric +{ + technique + { + pass + { + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_vp {} + fragment_program_ref SSAO/Volumetric_fp + { + param_named_auto cViewportSize viewport_size + param_named_auto cFov fov + } + + texture_unit // normals + { + content_type compositor SSAO/GBuffer mrt 1 + tex_address_mode clamp + filtering none + } + + texture_unit // view space position + { + content_type compositor SSAO/GBuffer mrt 2 + tex_address_mode clamp + filtering none + } + + texture_unit + { + texture 4InterleavedKMeansDisk8x4.png + tex_address_mode wrap + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/ShaderInstancing.material b/res/dist/media/materials/scripts/ShaderInstancing.material new file mode 100644 index 00000000000..913211bd4ae --- /dev/null +++ b/res/dist/media/materials/scripts/ShaderInstancing.material @@ -0,0 +1,380 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + + +//-------------------------------------------------------------- +// GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/ShaderBased_glsl_vs glsl +{ + source ShaderInstancing.vert + + preprocessor_defines DEPTH_SHADOWRECEIVER=1 + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/shadow_caster_glsl_vs glsl +{ + source ShaderInstancing.vert + preprocessor_defines DEPTH_SHADOWCASTER=1 + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/ShaderBased_dq_glsl_vs glsl +{ + source ShaderInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,DEPTH_SHADOWRECEIVER=1 + + includes_skeletal_animation true + +} + +vertex_program Ogre/Instancing/shadow_caster_dq_glsl_vs glsl +{ + source ShaderInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,DEPTH_SHADOWCASTER=1 + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/ShaderBased_dq_two_weights_glsl_vs glsl +{ + source ShaderInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,BONE_TWO_WEIGHTS,DEPTH_SHADOWRECEIVER=1 + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/shadow_caster_dq_two_weights_glsl_vs glsl +{ + source ShaderInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,BONE_TWO_WEIGHTS,DEPTH_SHADOWCASTER=1 + + includes_skeletal_animation true +} + + +//-------------------------------------------------------------- +// CG Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/ShaderBased_cg_vs cg +{ + source ShaderInstancing.cg + entry_point main_vs + profiles vs_3_0 vs_2_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/shadow_caster_cg_vs cg +{ + source ShaderInstancing.cg + entry_point main_vs + profiles vs_3_0 vs_2_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/ShaderBased_dq_cg_vs cg +{ + source ShaderInstancing.cg + entry_point main_vs + profiles vs_3_0 vs_2_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DST_DUAL_QUATERNION + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/shadow_caster_dq_cg_vs cg +{ + source ShaderInstancing.cg + entry_point main_vs + profiles vs_3_0 vs_2_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DST_DUAL_QUATERNION + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/ShaderBased_dq_two_weights_cg_vs cg +{ + source ShaderInstancing.cg + entry_point main_vs + profiles vs_3_0 vs_2_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DST_DUAL_QUATERNION -DBONE_TWO_WEIGHTS + + includes_skeletal_animation true +} + +vertex_program Ogre/Instancing/shadow_caster_dq_two_weights_cg_vs cg +{ + source ShaderInstancing.cg + entry_point main_vs + profiles vs_3_0 vs_2_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DST_DUAL_QUATERNION -DBONE_TWO_WEIGHTS + + includes_skeletal_animation true +} + + +//-------------------------------------------------------------- +// Unified CG/GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/ShaderBased_vs unified +{ + delegate Ogre/Instancing/ShaderBased_glsl_vs + delegate Ogre/Instancing/ShaderBased_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/shadow_caster_vs unified +{ + delegate Ogre/Instancing/shadow_caster_glsl_vs + delegate Ogre/Instancing/shadow_caster_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto depthRange scene_depth_range + } +} + +vertex_program Ogre/Instancing/ShaderBased_dq_vs unified +{ + delegate Ogre/Instancing/ShaderBased_dq_glsl_vs + delegate Ogre/Instancing/ShaderBased_dq_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/shadow_caster_dq_vs unified +{ + delegate Ogre/Instancing/shadow_caster_dq_glsl_vs + delegate Ogre/Instancing/shadow_caster_dq_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto depthRange shadow_scene_depth_range 0 + } +} + +vertex_program Ogre/Instancing/ShaderBased_dq_two_weights_vs unified +{ + delegate Ogre/Instancing/ShaderBased_dq_two_weights_glsl_vs + delegate Ogre/Instancing/ShaderBased_dq_two_weights_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/shadow_caster_dq_two_weights_vs unified +{ + delegate Ogre/Instancing/shadow_caster_dq_two_weights_glsl_vs + delegate Ogre/Instancing/shadow_caster_dq_two_weights_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto depthRange shadow_scene_depth_range 0 + + } +} + +material Examples/Instancing/ShaderBased/shadow_caster +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/shadow_caster_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + } + } +} + +material Examples/Instancing/ShaderBased/shadow_caster_dq +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/shadow_caster_dq_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + } + } +} + +material Examples/Instancing/ShaderBased/shadow_caster_dq_two_weights +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/shadow_caster_dq_two_weights_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + } + } +} + +abstract material Examples/Instancing/ShaderBased +{ + technique + { + shadow_caster_material Examples/Instancing/ShaderBased/shadow_caster + + pass + { + specular 1 1 1 1 12.5 + vertex_program_ref Ogre/Instancing/ShaderBased_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + } + } +} + +material Examples/Instancing/ShaderBased/Robot : Examples/Instancing/ShaderBased +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +abstract material Examples/Instancing/ShaderBased_dq +{ + technique + { + shadow_caster_material Examples/Instancing/ShaderBased/shadow_caster_dq + + pass + { + specular 1 1 1 1 12.5 + vertex_program_ref Ogre/Instancing/ShaderBased_dq_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + } + } +} + +material Examples/Instancing/ShaderBased/Robot_dq : Examples/Instancing/ShaderBased_dq +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +abstract material Examples/Instancing/ShaderBased_dq_two_weights +{ + technique + { + shadow_caster_material Examples/Instancing/ShaderBased/shadow_caster_dq_two_weights + + pass + { + diffuse 0.3 0.3 0.3 + specular 0.1 0.1 0.1 0.1 12.5 + vertex_program_ref Ogre/Instancing/ShaderBased_dq_two_weights_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + tex_address_mode clamp + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + } + } +} + +material Examples/Instancing/ShaderBased/spine_dq_two_weights : Examples/Instancing/ShaderBased_dq_two_weights +{ + set_texture_alias DiffuseMap circuit.dds +} diff --git a/res/dist/media/materials/scripts/ShaderSystem.material b/res/dist/media/materials/scripts/ShaderSystem.material new file mode 100644 index 00000000000..a164e08c489 --- /dev/null +++ b/res/dist/media/materials/scripts/ShaderSystem.material @@ -0,0 +1,20 @@ + +material Panels +{ + technique + { + pass + { + specular 0.64 0.64 0.64 32 0 + + texture_unit + { + texture Panels_Diffuse.png + } + } + + } + +} + + diff --git a/res/dist/media/materials/scripts/SharpenEdges.material b/res/dist/media/materials/scripts/SharpenEdges.material new file mode 100644 index 00000000000..865079deff2 --- /dev/null +++ b/res/dist/media/materials/scripts/SharpenEdges.material @@ -0,0 +1,66 @@ +fragment_program Ogre/Compositor/SharpenEdgesFP_cg cg +{ + source SharpenEdgesFP.cg + entry_point sharpenEdges_fp + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/SharpenEdgesFP_ps_2_a hlsl +{ + source SharpenEdgesFP.cg + entry_point sharpenEdges_fp + target ps_2_a +} + +fragment_program Ogre/Compositor/SharpenEdgesFP_glsles glsles +{ + source SharpenEdgesFP.glsles +} + +fragment_program Ogre/Compositor/SharpenEdgesFP unified +{ + delegate Ogre/Compositor/SharpenEdgesFP_ps_2_a + delegate Ogre/Compositor/SharpenEdgesFP_glsles + delegate Ogre/Compositor/SharpenEdgesFP_cg + + default_params + { + param_named_auto vTexelSize inverse_texture_size 0 + } +} + +material Ogre/Compositor/SharpenEdges +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + //DirectX 9.0 HLSL Vertex Shader vs_1_1 + //vertex_program_ref PostFilters/SharpenEdgesVP + //{ + //} + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + //DirectX 9.0 HLSL Pixel Shader ps_2_0 + fragment_program_ref Ogre/Compositor/SharpenEdgesFP + { + } + + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + } + } +} diff --git a/res/dist/media/materials/scripts/StdQuad_vp.program b/res/dist/media/materials/scripts/StdQuad_vp.program new file mode 100644 index 00000000000..f1f51d285d8 --- /dev/null +++ b/res/dist/media/materials/scripts/StdQuad_vp.program @@ -0,0 +1,162 @@ +vertex_program Ogre/Compositor/StdQuad_Cg_vp cg +{ + source StdQuad_vp.cg + entry_point StdQuad_vp + profiles vs_4_0 vs_2_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_Tex2_Cg_vp cg +{ + source StdQuad_vp.cg + entry_point StdQuad_Tex2_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_Tex2a_Cg_vp cg +{ + source StdQuad_vp.cg + entry_point StdQuad_Tex2a_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_Tex3_Cg_vp cg +{ + source StdQuad_vp.cg + entry_point StdQuad_Tex3_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_Tex4_Cg_vp cg +{ + source StdQuad_vp.cg + entry_point StdQuad_Tex4_vp + profiles vs_4_0 vs_1_1 arbvp1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_GLSL_vp glsl +{ + source StdQuad_vp.glsl +} + +vertex_program Ogre/Compositor/StdQuad_GLSLES_vp glsles +{ + source StdQuad_vp.glsles + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_Tex2_GLSLES_vp glsles +{ + source StdQuad_Tex2_vp.glsles + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_Tex2a_GLSLES_vp glsles +{ + source StdQuad_Tex2a_vp.glsles + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_Tex3_GLSLES_vp glsles +{ + source StdQuad_Tex3_vp.glsles + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_Tex4_GLSLES_vp glsles +{ + source StdQuad_Tex4_vp.glsles + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + +vertex_program Ogre/Compositor/StdQuad_HLSL_vp hlsl +{ + source StdQuad_vp.hlsl + entry_point StdQuad_vp + target vs_2_0 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } +} + + + +// Unified definitions +vertex_program Ogre/Compositor/StdQuad_vp unified +{ + delegate Ogre/Compositor/StdQuad_GLSLES_vp + delegate Ogre/Compositor/StdQuad_Cg_vp +} + +vertex_program Ogre/Compositor/StdQuad_NoCG_vp unified +{ + delegate Ogre/Compositor/StdQuad_GLSL_vp + delegate Ogre/Compositor/StdQuad_GLSLES_vp + delegate Ogre/Compositor/StdQuad_HLSL_vp +} + +vertex_program Ogre/Compositor/StdQuad_Tex2_vp unified +{ + delegate Ogre/Compositor/StdQuad_Tex2_GLSLES_vp + delegate Ogre/Compositor/StdQuad_Tex2_Cg_vp +} + +vertex_program Ogre/Compositor/StdQuad_Tex2a_vp unified +{ + delegate Ogre/Compositor/StdQuad_Tex2a_GLSLES_vp + delegate Ogre/Compositor/StdQuad_Tex2a_Cg_vp +} + +vertex_program Ogre/Compositor/StdQuad_Tex3_vp unified +{ + delegate Ogre/Compositor/StdQuad_Tex3_GLSLES_vp + delegate Ogre/Compositor/StdQuad_Tex3_Cg_vp +} + +vertex_program Ogre/Compositor/StdQuad_Tex4_vp unified +{ + delegate Ogre/Compositor/StdQuad_Tex4_GLSLES_vp + delegate Ogre/Compositor/StdQuad_Tex4_Cg_vp +} + diff --git a/res/dist/media/materials/scripts/TextureAtlasSampleOrg.tai b/res/dist/media/materials/scripts/TextureAtlasSampleOrg.tai new file mode 100644 index 00000000000..ff74d83ee97 --- /dev/null +++ b/res/dist/media/materials/scripts/TextureAtlasSampleOrg.tai @@ -0,0 +1,36 @@ +# TextureAtlasSampleOrg.tai +# AtlasCreationTool.exe -width 2048 -height 2048 -o TextureAtlasSampleOrg +# +# , , , , , , , +# +# Texture can be found in texture atlas , i.e., +# TextureAtlasSampleOrg.png of type with texture coordinates boundary given by: +# A = ( , ) +# B = ( + , + ) +# +# where coordinates (0,0) and (1,1) of the original texture map correspond +# to coordinates A and B, respectively, in the texture atlas. +# If the atlas is a volume texture then is the w-coordinate +# to use the access the appropriate slice in the volume atlas. + +ogrelogo-small.jpg TextureAtlasSampleOrg0.png, 0, 2D, 0.000000, 0.000000, 0.000000, 0.500000, 0.500000 +img2.png TextureAtlasSampleOrg0.png, 0, 2D, 0.500000, 0.000000, 0.000000, 0.250000, 0.500000 +radial.png TextureAtlasSampleOrg0.png, 0, 2D, 0.750000, 0.000000, 0.000000, 0.250000, 0.500000 +1d_SPIRAL.png TextureAtlasSampleOrg0.png, 0, 2D, 0.000000, 0.500000, 0.000000, 0.125000, 0.250000 +img1.png TextureAtlasSampleOrg0.png, 0, 2D, 0.125000, 0.500000, 0.000000, 0.125000, 0.250000 +Dirt.jpg TextureAtlasSampleOrg0.png, 0, 2D, 0.250000, 0.500000, 0.000000, 0.125000, 0.250000 +flare.png TextureAtlasSampleOrg0.png, 0, 2D, 0.375000, 0.500000, 0.000000, 0.125000, 0.250000 +rockwall.tga TextureAtlasSampleOrg0.png, 0, 2D, 0.500000, 0.500000, 0.000000, 0.125000, 0.250000 +steelhead.png TextureAtlasSampleOrg0.png, 0, 2D, 0.625000, 0.500000, 0.000000, 0.125000, 0.250000 +RustyBarrel.png TextureAtlasSampleOrg0.png, 0, 2D, 0.750000, 0.500000, 0.000000, 0.125000, 0.250000 +NMBalls.png TextureAtlasSampleOrg0.png, 0, 2D, 0.875000, 0.500000, 0.000000, 0.125000, 0.250000 +terr_dirt-grass.jpg TextureAtlasSampleOrg0.png, 0, 2D, 0.000000, 0.750000, 0.000000, 0.125000, 0.250000 +SmallLeaf_BP.png TextureAtlasSampleOrg0.png, 0, 2D, 0.125000, 0.750000, 0.000000, 0.062500, 0.250000 +1d_debug.png TextureAtlasSampleOrg0.png, 0, 2D, 0.187500, 0.750000, 0.000000, 0.062500, 0.125000 +checker.png TextureAtlasSampleOrg0.png, 0, 2D, 0.250000, 0.750000, 0.000000, 0.062500, 0.125000 +spotlight_image.png TextureAtlasSampleOrg0.png, 0, 2D, 0.312500, 0.750000, 0.000000, 0.062500, 0.125000 +nm_bk.png TextureAtlasSampleOrg0.png, 0, 2D, 0.375000, 0.750000, 0.000000, 0.062500, 0.125000 +dirt01.jpg TextureAtlasSampleOrg0.png, 0, 2D, 0.437500, 0.750000, 0.000000, 0.062500, 0.125000 +tusk.jpg TextureAtlasSampleOrg0.png, 0, 2D, 0.500000, 0.750000, 0.000000, 0.062500, 0.125000 +LowRes.png TextureAtlasSampleOrg0.png, 0, 2D, 0.562500, 0.750000, 0.000000, 0.015625, 0.031250 +scr-up-p.png TextureAtlasSampleOrg0.png, 0, 2D, 0.578125, 0.750000, 0.000000, 0.007813, 0.015625 diff --git a/res/dist/media/materials/scripts/TextureAtlasSampleWrap.tai b/res/dist/media/materials/scripts/TextureAtlasSampleWrap.tai new file mode 100644 index 00000000000..c5e319a7dbc --- /dev/null +++ b/res/dist/media/materials/scripts/TextureAtlasSampleWrap.tai @@ -0,0 +1,36 @@ +# TextureAtlasSampleWrap.tai +# AtlasCreationTool.exe -width 2048 -height 2048 -o TextureAtlasSampleWrap +# +# , , , , , , , +# +# Texture can be found in texture atlas , i.e., +# TextureAtlasSampleWrap.png of type with texture coordinates boundary given by: +# A = ( , ) +# B = ( + , + ) +# +# where coordinates (0,0) and (1,1) of the original texture map correspond +# to coordinates A and B, respectively, in the texture atlas. +# If the atlas is a volume texture then is the w-coordinate +# to use the access the appropriate slice in the volume atlas. + +ogrelogo-small.jpg TextureAtlasSampleWrap0.png, 0, 2D, 0.125000, 0.125000, 0.000000, 0.250000, 0.250000 +img2.png TextureAtlasSampleWrap0.png, 0, 2D, 0.562500, 0.125000, 0.000000, 0.125000, 0.250000 +radial.png TextureAtlasSampleWrap0.png, 0, 2D, 0.812500, 0.125000, 0.000000, 0.125000, 0.250000 +1d_SPIRAL.png TextureAtlasSampleWrap0.png, 0, 2D, 0.031250, 0.562500, 0.000000, 0.062500, 0.125000 +img1.png TextureAtlasSampleWrap0.png, 0, 2D, 0.156250, 0.562500, 0.000000, 0.062500, 0.125000 +Dirt.jpg TextureAtlasSampleWrap0.png, 0, 2D, 0.281250, 0.562500, 0.000000, 0.062500, 0.125000 +flare.png TextureAtlasSampleWrap0.png, 0, 2D, 0.406250, 0.562500, 0.000000, 0.062500, 0.125000 +rockwall.tga TextureAtlasSampleWrap0.png, 0, 2D, 0.531250, 0.562500, 0.000000, 0.062500, 0.125000 +steelhead.png TextureAtlasSampleWrap0.png, 0, 2D, 0.656250, 0.562500, 0.000000, 0.062500, 0.125000 +RustyBarrel.png TextureAtlasSampleWrap0.png, 0, 2D, 0.781250, 0.562500, 0.000000, 0.062500, 0.125000 +NMBalls.png TextureAtlasSampleWrap0.png, 0, 2D, 0.906250, 0.562500, 0.000000, 0.062500, 0.125000 +terr_dirt-grass.jpg TextureAtlasSampleWrap0.png, 0, 2D, 0.031250, 0.812500, 0.000000, 0.062500, 0.125000 +SmallLeaf_BP.png TextureAtlasSampleWrap0.png, 0, 2D, 0.140625, 0.812500, 0.000000, 0.031250, 0.125000 +1d_debug.png TextureAtlasSampleWrap0.png, 0, 2D, 0.203125, 0.781250, 0.000000, 0.031250, 0.062500 +checker.png TextureAtlasSampleWrap0.png, 0, 2D, 0.265625, 0.781250, 0.000000, 0.031250, 0.062500 +spotlight_image.png TextureAtlasSampleWrap0.png, 0, 2D, 0.328125, 0.781250, 0.000000, 0.031250, 0.062500 +nm_bk.png TextureAtlasSampleWrap0.png, 0, 2D, 0.390625, 0.781250, 0.000000, 0.031250, 0.062500 +dirt01.jpg TextureAtlasSampleWrap0.png, 0, 2D, 0.453125, 0.781250, 0.000000, 0.031250, 0.062500 +tusk.jpg TextureAtlasSampleWrap0.png, 0, 2D, 0.515625, 0.781250, 0.000000, 0.031250, 0.062500 +LowRes.png TextureAtlasSampleWrap0.png, 0, 2D, 0.566406, 0.757813, 0.000000, 0.007813, 0.015625 +scr-up-p.png TextureAtlasSampleWrap0.png, 0, 2D, 0.580078, 0.753906, 0.000000, 0.003906, 0.007813 diff --git a/res/dist/media/materials/scripts/Tiling.material b/res/dist/media/materials/scripts/Tiling.material new file mode 100644 index 00000000000..e85f47f6394 --- /dev/null +++ b/res/dist/media/materials/scripts/Tiling.material @@ -0,0 +1,50 @@ +fragment_program Ogre/Compositor/Tiling_Cg_FP cg +{ + source TilingFP.cg + entry_point Tiling_ps + profiles ps_4_0 ps_2_0 arbfp1 +} + +fragment_program Ogre/Compositor/Tiling_GLSLES_FP glsles +{ + source TilingFP.glsles +} + +fragment_program Ogre/Compositor/TilingFP unified +{ + delegate Ogre/Compositor/Tiling_GLSLES_FP + delegate Ogre/Compositor/Tiling_Cg_FP +} + +material Ogre/Compositor/Tiling +{ + technique + { + + pass + { + cull_hardware none + cull_software none + depth_func always_pass + + vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp + { + } + + //DirectX 9.0 HLSL Pixel Shader ps_2_0 + fragment_program_ref Ogre/Compositor/TilingFP + { + param_named NumTiles float 75.0 + param_named Threshold float 0.15 + } + + texture_unit RT + { + tex_coord_set 0 + tex_address_mode clamp + filtering trilinear + } + + } + } +} diff --git a/res/dist/media/materials/scripts/VTFInstancing.material b/res/dist/media/materials/scripts/VTFInstancing.material new file mode 100644 index 00000000000..80a085912f5 --- /dev/null +++ b/res/dist/media/materials/scripts/VTFInstancing.material @@ -0,0 +1,438 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//-------------------------------------------------------------- +// GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/VTF_glsl_vs glsl +{ + source VTFInstancing.vert + + preprocessor_defines DEPTH_SHADOWRECEIVER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_glsl_vs glsl +{ + source VTFInstancing.vert + + preprocessor_defines DEPTH_SHADOWCASTER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + +vertex_program Ogre/Instancing/VTF_dq_glsl_vs glsl +{ + source VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,DEPTH_SHADOWRECEIVER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_dq_glsl_vs glsl +{ + source VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,DEPTH_SHADOWCASTER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + +vertex_program Ogre/Instancing/VTF_dq_two_weights_glsl_vs glsl +{ + source VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,BONE_TWO_WEIGHTS,DEPTH_SHADOWRECEIVER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 2 + } +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_dq_two_weights_glsl_vs glsl +{ + source VTFInstancing.vert + + preprocessor_defines ST_DUAL_QUATERNION,BONE_TWO_WEIGHTS,DEPTH_SHADOWCASTER=1 + + uses_vertex_texture_fetch true + + default_params + { + param_named matrixTexture int 0 + } +} + +//-------------------------------------------------------------- +// CG Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/VTF_cg_vs cg +{ + source VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_cg_vs cg +{ + source VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF_dq_cg_vs cg +{ + source VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DST_DUAL_QUATERNION + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_dq_cg_vs cg +{ + source VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DST_DUAL_QUATERNION + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF_dq_two_weights_cg_vs cg +{ + source VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER -DST_DUAL_QUATERNION -DBONE_TWO_WEIGHTS + + uses_vertex_texture_fetch true +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_dq_two_weights_cg_vs cg +{ + source VTFInstancing.cg + entry_point main_vs + profiles vs_3_0 vp40 + + compile_arguments -DDEPTH_SHADOWCASTER -DST_DUAL_QUATERNION -DBONE_TWO_WEIGHTS + + uses_vertex_texture_fetch true +} + +//-------------------------------------------------------------- +// Unified CG/GLSL Programs +//-------------------------------------------------------------- +vertex_program Ogre/Instancing/VTF_vs unified +{ + delegate Ogre/Instancing/VTF_glsl_vs + delegate Ogre/Instancing/VTF_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_vs unified +{ + delegate Ogre/Instancing/VTF/shadow_caster_glsl_vs + delegate Ogre/Instancing/VTF/shadow_caster_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +vertex_program Ogre/Instancing/VTF_dq_vs unified +{ + delegate Ogre/Instancing/VTF_dq_glsl_vs + delegate Ogre/Instancing/VTF_dq_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_dq_vs unified +{ + delegate Ogre/Instancing/VTF/shadow_caster_dq_glsl_vs + delegate Ogre/Instancing/VTF/shadow_caster_dq_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +vertex_program Ogre/Instancing/VTF_dq_two_weights_vs unified +{ + delegate Ogre/Instancing/VTF_dq_two_weights_glsl_vs + delegate Ogre/Instancing/VTF_dq_two_weights_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + + param_named_auto depthRange shadow_scene_depth_range 0 + param_named_auto texViewProjMatrix texture_viewproj_matrix 0 + } +} + +vertex_program Ogre/Instancing/VTF/shadow_caster_dq_two_weights_vs unified +{ + delegate Ogre/Instancing/VTF/shadow_caster_dq_two_weights_glsl_vs + delegate Ogre/Instancing/VTF/shadow_caster_dq_two_weights_cg_vs + + default_params + { + param_named_auto viewProjMatrix viewproj_matrix + param_named_auto depthRange scene_depth_range + } +} + +material Examples/Instancing/VTF/shadow_caster +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/shadow_caster_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/shadow_caster_dq +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/shadow_caster_dq_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/shadow_caster_dq_two_weights +{ + technique + { + pass + { + vertex_program_ref Ogre/Instancing/VTF/shadow_caster_dq_two_weights_vs + { + } + fragment_program_ref Ogre/Instancing/shadow_caster_ps + { + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +abstract material Examples/Instancing/VTF +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/shadow_caster + + pass + { + specular 1 1 1 1 12.5 + vertex_program_ref Ogre/Instancing/VTF_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +abstract material Examples/Instancing/VTF_dq +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/shadow_caster_dq + + pass + { + specular 1 1 1 1 12.5 + vertex_program_ref Ogre/Instancing/VTF_dq_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +abstract material Examples/Instancing/VTF_dq_two_weights +{ + technique + { + shadow_caster_material Examples/Instancing/VTF/shadow_caster_dq_two_weights + + pass + { + diffuse 0.3 0.3 0.3 + specular 0.1 0.1 0.1 0.1 12.5 + vertex_program_ref Ogre/Instancing/VTF_dq_two_weights_vs + { + } + + fragment_program_ref Ogre/Instancing_ps + { + } + + texture_unit Diffuse + { + texture_alias DiffuseMap + tex_address_mode clamp + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + + texture_unit InstancingVTF + { + binding_type vertex + filtering none + } + } + } +} + +material Examples/Instancing/VTF/Robot : Examples/Instancing/VTF +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +material Examples/Instancing/VTF/Robot_dq : Examples/Instancing/VTF_dq +{ + set_texture_alias DiffuseMap r2skin.jpg +} + +material Examples/Instancing/VTF/spine_dq_two_weights : Examples/Instancing/VTF_dq_two_weights +{ + set_texture_alias DiffuseMap circuit.dds +} diff --git a/res/dist/media/materials/scripts/VarianceShadowmap.material b/res/dist/media/materials/scripts/VarianceShadowmap.material new file mode 100644 index 00000000000..16d9e594567 --- /dev/null +++ b/res/dist/media/materials/scripts/VarianceShadowmap.material @@ -0,0 +1,103 @@ + +// Shadow Caster __________________________________________________ + + +vertex_program VarianceShadowMapping/ShadowCasterVP cg +{ + source varianceshadowcastervp.cg + entry_point main + profiles arbvp1 vs_2_x + + default_params + { + param_named_auto uModelViewProjection worldviewproj_matrix + } +} + +fragment_program VarianceShadowMapping/ShadowCasterFP cg +{ + source varianceshadowcasterfp.cg + entry_point main + profiles arbfp1 ps_2_x + + default_params + { + param_named uDepthOffset float 1.0 + param_named_auto uProjection projection_matrix + } +} + +material VarianceShadowMapping/ShadowCaster +{ + technique default + { + // Z-write only pass + pass Z-write + { + //Instead of using depth_bias, we'll be implementing it manually + + vertex_program_ref VarianceShadowMapping/ShadowCasterVP + { + } + fragment_program_ref VarianceShadowMapping/ShadowCasterFP + { + } + } + } +} + + + +// Shadow Receiver ________________________________________________ + +vertex_program VarianceShadowMapping/ShadowReceiverVP cg +{ + source varianceshadowreceivervp.cg + entry_point main + profiles arbvp1 vs_2_x + + default_params + { + param_named_auto uModelViewProjection worldviewproj_matrix + param_named_auto uLightPosition light_position_object_space 0 + param_named_auto uModel world_matrix + param_named_auto uTextureViewProjection texture_viewproj_matrix + } +} + +fragment_program VarianceShadowMapping/ShadowReceiverFP cg +{ + source varianceshadowreceiverfp.cg + entry_point main + profiles arbfp1 ps_2_x + + default_params + { + param_named uSTexWidth float 512.0 + param_named uSTexHeight float 512.0 + } +} + +material VarianceShadowMapping/ShadowReceiver +{ + technique default + { + pass lighting + { + vertex_program_ref VarianceShadowMapping/ShadowReceiverVP + { + } + + fragment_program_ref VarianceShadowMapping/ShadowReceiverFP + { + } + + // we won't rely on hardware specific filtering of z-tests + texture_unit ShadowMap + { + tex_address_mode clamp + filtering none + } + } + } +} diff --git a/res/dist/media/materials/scripts/facial.material b/res/dist/media/materials/scripts/facial.material new file mode 100644 index 00000000000..6a481980d99 --- /dev/null +++ b/res/dist/media/materials/scripts/facial.material @@ -0,0 +1,98 @@ + +material drbunsen_head +{ + technique + { + pass + { + ambient 0.25 0.25 0.25 + diffuse 1.0 1.0 1.0 + + texture_unit + { + texture Dr_Bunsen_Head.jpg + } + } + } +} + +material drbunsen_eye +{ + technique + { + pass + { + ambient 0.25 0.25 0.25 + diffuse 1.0 1.0 1.0 + + } + } +} + +material drbunsen_teeth +{ + technique + { + pass + { + ambient 0.25 0.25 0.25 + diffuse 1.0 1.0 1.0 + + } + } +} + +material drbunsen_tongue +{ + technique + { + pass + { + ambient 0.25 0.25 0.25 + diffuse 1.0 0.1 0.1 + + } + } +} + +material drbunsen_gums +{ + technique + { + pass + { + ambient 0.25 0.25 0.25 + diffuse 1.0 0.1 0.1 + + } + } +} + +material drbunsen_glasses +{ + technique + { + pass + { + depth_write off + scene_blend modulate + ambient 0.25 0.25 0.25 + diffuse 0.75 0.75 0.75 + + } + } +} + +material drbunsen_glasses_frame +{ + technique + { + pass + { + ambient 0.25 0.25 0.25 + diffuse 0.35 0.18 0 1 + + } + } +} + diff --git a/res/dist/media/materials/scripts/hdr.material b/res/dist/media/materials/scripts/hdr.material new file mode 100644 index 00000000000..6cc937c1f94 --- /dev/null +++ b/res/dist/media/materials/scripts/hdr.material @@ -0,0 +1,332 @@ +// Downsample a 2x2 area & turn into luminence (unclamped) +fragment_program Ogre/Compositor/HDR/downscale2x2LuminenceHLSL_fp hlsl +{ + source hdr.hlsl + entry_point downscale2x2Luminence + target ps_2_0 +} +fragment_program Ogre/Compositor/HDR/downscale2x2LuminenceGLSL_fp glsl +{ + source hdr_downscale2x2luminence.glsl + default_params + { + param_named inRTT int 0 + } +} +fragment_program Ogre/Compositor/HDR/downscale2x2LuminenceGLSLES_fp glsles +{ + source hdr_downscale2x2luminence.glsles + default_params + { + param_named inRTT int 0 + } +} +fragment_program Ogre/Compositor/HDR/downscale2x2Luminence_fp unified +{ + delegate Ogre/Compositor/HDR/downscale2x2LuminenceGLSL_fp + delegate Ogre/Compositor/HDR/downscale2x2LuminenceGLSLES_fp + delegate Ogre/Compositor/HDR/downscale2x2LuminenceHLSL_fp + default_params + { + param_named_auto texelSize inverse_texture_size 0 + } +} + +material Ogre/Compositor/HDR/Downsample2x2Luminence +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_NoCG_vp + { + } + fragment_program_ref Ogre/Compositor/HDR/downscale2x2Luminence_fp + { + } + + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering none + } + } + } +} + +// Downsample a 3x3 area +fragment_program Ogre/Compositor/HDR/downscale3x3HLSL_fp hlsl +{ + source hdr.hlsl + entry_point downscale3x3 + target ps_2_0 +} +fragment_program Ogre/Compositor/HDR/downscale3x3GLSLES_fp glsles +{ + source hdr_downscale3x3.glsles + default_params + { + param_named inRTT int 0 + } +} +fragment_program Ogre/Compositor/HDR/downscale3x3GLSL_fp glsl +{ + source hdr_downscale3x3.glsl + default_params + { + param_named inRTT int 0 + } +} +fragment_program Ogre/Compositor/HDR/downscale3x3_fp unified +{ + delegate Ogre/Compositor/HDR/downscale3x3GLSL_fp + delegate Ogre/Compositor/HDR/downscale3x3GLSLES_fp + delegate Ogre/Compositor/HDR/downscale3x3HLSL_fp + default_params + { + param_named_auto texelSize inverse_texture_size 0 + } +} + + +material Ogre/Compositor/HDR/Downsample3x3 +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_NoCG_vp + { + } + fragment_program_ref Ogre/Compositor/HDR/downscale3x3_fp + { + } + + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering none + } + } + } +} + +// Downsample a 3x3 area and perform a brightness filter pass +fragment_program Ogre/Compositor/HDR/downscale3x3brightpassHLSL_fp hlsl +{ + source hdr.hlsl + entry_point downscale3x3brightpass + target ps_2_0 +} +fragment_program Ogre/Compositor/HDR/utils_fp glsl +{ + source hdr_tonemap_util.glsl +} +fragment_program Ogre/Compositor/HDR/downscale3x3brightpassGLSL_fp glsl +{ + source hdr_downscale3x3brightpass.glsl + // re-use common functions + attach Ogre/Compositor/HDR/utils_fp + default_params + { + param_named inRTT int 0 + param_named inLum int 1 + } +} +fragment_program Ogre/Compositor/HDR/downscale3x3brightpassGLSLES_fp glsles +{ + source hdr_downscale3x3brightpass.glsles + default_params + { + param_named inRTT int 0 + param_named inLum int 1 + } +} +fragment_program Ogre/Compositor/HDR/downscale3x3brightpass_fp unified +{ + delegate Ogre/Compositor/HDR/downscale3x3brightpassGLSL_fp + delegate Ogre/Compositor/HDR/downscale3x3brightpassGLSLES_fp + delegate Ogre/Compositor/HDR/downscale3x3brightpassHLSL_fp + default_params + { + param_named_auto texelSize inverse_texture_size 0 + } +} + + +material Ogre/Compositor/HDR/Downsample3x3Brightpass +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_NoCG_vp + { + } + fragment_program_ref Ogre/Compositor/HDR/downscale3x3brightpass_fp + { + } + + // Scene + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering none + } + // Luminence + texture_unit + { + tex_address_mode clamp + filtering none + } + } + } +} + +// Bloom an area using gaussian distribution +fragment_program Ogre/Compositor/HDR/bloomHLSL_fp hlsl +{ + source hdr.hlsl + entry_point bloom + target ps_2_0 +} +fragment_program Ogre/Compositor/HDR/bloomGLSL_fp glsl +{ + source hdr_bloom.glsl + default_params + { + param_named inRTT int 0 + } +} +fragment_program Ogre/Compositor/HDR/bloomGLSLES_fp glsles +{ + source hdr_bloom.glsles + default_params + { + param_named inRTT int 0 + } +} +fragment_program Ogre/Compositor/HDR/bloom_fp unified +{ + delegate Ogre/Compositor/HDR/bloomGLSL_fp + delegate Ogre/Compositor/HDR/bloomGLSLES_fp + delegate Ogre/Compositor/HDR/bloomHLSL_fp +} + + +material Ogre/Compositor/HDR/GaussianBloom +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_NoCG_vp + { + } + fragment_program_ref Ogre/Compositor/HDR/bloom_fp + { + } + + // Input + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + filtering none + } + } + } +} + + +// Perform final tone mapping +fragment_program Ogre/Compositor/HDR/finaltonemappingHLSL_fp hlsl +{ + source hdr.hlsl + entry_point finalToneMapping + target ps_2_0 +} +fragment_program Ogre/Compositor/HDR/finaltonemappingGLSL_fp glsl +{ + source hdr_finalToneMapping.glsl + // re-use common functions + attach Ogre/Compositor/HDR/utils_fp + default_params + { + param_named inRTT int 0 + param_named inBloom int 1 + param_named inLum int 2 + } +} +fragment_program Ogre/Compositor/HDR/finaltonemappingGLSLES_fp glsles +{ + source hdr_finalToneMapping.glsles + default_params + { + param_named inRTT int 0 + param_named inBloom int 1 + param_named inLum int 2 + } +} +fragment_program Ogre/Compositor/HDR/finaltonemapping_fp unified +{ + delegate Ogre/Compositor/HDR/finaltonemappingGLSL_fp + delegate Ogre/Compositor/HDR/finaltonemappingGLSLES_fp + delegate Ogre/Compositor/HDR/finaltonemappingHLSL_fp +} + +material Ogre/Compositor/HDR/ToneMapping +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_check off + + vertex_program_ref Ogre/Compositor/StdQuad_NoCG_vp + { + } + fragment_program_ref Ogre/Compositor/HDR/finaltonemapping_fp + { + } + + // Scene + texture_unit + { + tex_coord_set 0 + tex_address_mode clamp + } + // Bloom + texture_unit + { + tex_address_mode clamp + } + // Luminence + texture_unit + { + tex_address_mode clamp + } + } + } +} diff --git a/res/dist/media/materials/scripts/instancing.material b/res/dist/media/materials/scripts/instancing.material new file mode 100644 index 00000000000..3162a49b9c0 --- /dev/null +++ b/res/dist/media/materials/scripts/instancing.material @@ -0,0 +1,185 @@ + +vertex_program InstancingCg cg +{ + source instancing.cg + profiles vs_2_0 + entry_point instancing_vp + + default_params + { + param_named_auto ambient ambient_light_colour + param_named_auto lightDiffuseColour derived_light_diffuse_colour 0 + param_named_auto lightPos light_position 0 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} +vertex_program InstancingShadowCasterCg cg +{ + source instancing.cg + profiles vs_2_0 + entry_point instancingCaster_vp + default_params + { + param_named_auto ambient ambient_light_colour + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} +vertex_program CrowdCg cg +{ + source instancing.cg + profiles vs_2_0 + entry_point crowd_vp + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto numBones custom 0 + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto lightPos light_position 0 + param_named_auto lightDiffuseColour derived_light_diffuse_colour 0 + param_named_auto ambient ambient_light_colour + } +} +vertex_program CrowdShadowCasterCg cg +{ + source instancing.cg + profiles vs_2_0 + entry_point crowdCaster_vp + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto numBones custom 0 + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto ambient ambient_light_colour + } +} + + +vertex_program InstancingGLSL glsl +{ + source instancingVp.glsl + preprocessor_defines SHADOW_CASTER=0 + default_params + { + param_named_auto ambient ambient_light_colour + param_named_auto lightDiffuseColour derived_light_diffuse_colour 0 + param_named_auto lightPos light_position 0 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} +vertex_program InstancingShadowCasterGLSL glsl +{ + source instancingVp.glsl + preprocessor_defines SHADOW_CASTER=1 + default_params + { + param_named_auto ambient ambient_light_colour + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} +vertex_program CrowdGLSL glsl +{ + source crowdVp.glsl + preprocessor_defines SHADOW_CASTER=0 + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto numBones custom 0 + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto lightPos light_position 0 + param_named_auto lightDiffuseColour derived_light_diffuse_colour 0 + param_named_auto ambient ambient_light_colour + } +} +vertex_program CrowdShadowCasterGLSL glsl +{ + source crowdVp.glsl + preprocessor_defines SHADOW_CASTER=1 + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto numBones custom 0 + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto ambient ambient_light_colour + } +} + +vertex_program InstancingGLSLES glsles +{ + source instancingVp.glsles + preprocessor_defines SHADOW_CASTER=0 + default_params + { + param_named_auto ambient ambient_light_colour + param_named_auto lightDiffuseColour light_diffuse_colour 0 + param_named_auto lightPos light_position 0 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} +vertex_program InstancingShadowCasterGLSLES glsles +{ + source instancingVp.glsles + preprocessor_defines SHADOW_CASTER=1 + default_params + { + param_named_auto ambient ambient_light_colour + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} +vertex_program CrowdGLSLES glsles +{ + source crowdVp.glsles + preprocessor_defines SHADOW_CASTER=0 + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto numBones custom 0 + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto lightPos light_position 0 + param_named_auto lightDiffuseColour light_diffuse_colour 0 + param_named_auto ambient ambient_light_colour + } +} +vertex_program CrowdShadowCasterGLSLES glsles +{ + source crowdVp.glsles + preprocessor_defines SHADOW_CASTER=1 + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto numBones custom 0 + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Instancing unified +{ + delegate InstancingGLSL + delegate InstancingGLSLES + delegate InstancingCg +} +vertex_program InstancingShadowCaster unified +{ + delegate InstancingShadowCasterGLSL + delegate InstancingShadowCasterGLSLES + delegate InstancingShadowCasterCg +} +vertex_program Crowd unified +{ + delegate CrowdGLSL + delegate CrowdGLSLES + delegate CrowdCg +} +vertex_program CrowdShadowCaster unified +{ + delegate CrowdShadowCasterGLSL + delegate CrowdShadowCasterGLSLES + delegate CrowdShadowCasterCg +} + diff --git a/res/dist/media/materials/scripts/pssm.material b/res/dist/media/materials/scripts/pssm.material new file mode 100644 index 00000000000..19bea30e3bc --- /dev/null +++ b/res/dist/media/materials/scripts/pssm.material @@ -0,0 +1,226 @@ +// declare the vertex shader (CG for the language) +vertex_program PSSM/shadow_caster_vsCg cg +{ + // source file + source pssm.cg + // will run on vertex shader 1.1+ + profiles vs_1_1 arbvp1 + // entry function + entry_point shadow_caster_vs + + default_params + { + param_named_auto wvpMat worldviewproj_matrix + // this is the scene's depth range + //param_named_auto depthRange scene_depth_range + //param_named_auto optimalAdustFactor custom 0 + } +} + +// declare the fragment shader (CG for the language) +fragment_program PSSM/shadow_caster_psCg cg +{ + // source file + source pssm.cg + // will run on pixel shader 2.0+ + profiles ps_2_0 arbfp1 + // entry function + entry_point shadow_caster_ps + + default_params + { + } +} + +// declare the vertex shader (GLSL ES for the language) +vertex_program PSSM/shadow_caster_vsGLSLES glsles +{ + // source file + source pssmCasterVp.glsles + // will run on GLSL ES + profiles glsles + + default_params + { + param_named_auto worldViewProjMatrix worldviewproj_matrix + // this is the scene's depth range + //param_named_auto depthRange scene_depth_range + //param_named_auto optimalAdustFactor custom 0 + } +} + +// declare the fragment shader (GLSL ES for the language) +fragment_program PSSM/shadow_caster_psGLSLES glsles +{ + // source file + source pssmCasterFp.glsles + // will run on GLSL ES + profiles glsles + + default_params + { + } +} + +vertex_program PSSM/shadow_caster_vs unified +{ + delegate PSSM/shadow_caster_vsGLSLES + delegate PSSM/shadow_caster_vsCg +} + +fragment_program PSSM/shadow_caster_ps unified +{ + delegate PSSM/shadow_caster_psGLSLES + delegate PSSM/shadow_caster_psCg +} + +material PSSM/shadow_caster +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref PSSM/shadow_caster_vs + { + } + + fragment_program_ref PSSM/shadow_caster_ps + { + } + } + } +} + +vertex_program PSSM/shadow_receiver_vsCg cg +{ + source pssm.cg + profiles vs_1_1 arbvp1 + entry_point shadow_receiver_vs + + default_params + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProjMatrix worldviewproj_matrix + param_named_auto texWorldViewProjMatrix0 texture_worldviewproj_matrix 0 + param_named_auto texWorldViewProjMatrix1 texture_worldviewproj_matrix 1 + param_named_auto texWorldViewProjMatrix2 texture_worldviewproj_matrix 2 + //param_named_auto depthRange0 shadow_scene_depth_range 0 + //param_named_auto depthRange1 shadow_scene_depth_range 1 + //param_named_auto depthRange2 shadow_scene_depth_range 2 + } +} + +fragment_program PSSM/shadow_receiver_psCg cg +{ + source pssm.cg + profiles ps_2_x arbfp1 + entry_point shadow_receiver_ps + + default_params + { + param_named_auto lightDiffuse derived_light_diffuse_colour 0 + param_named_auto lightSpecular derived_light_specular_colour 0 + param_named_auto ambient derived_ambient_light_colour + param_named_auto invShadowMapSize0 inverse_texture_size 0 + param_named_auto invShadowMapSize1 inverse_texture_size 1 + param_named_auto invShadowMapSize2 inverse_texture_size 2 + //param_named pssmSplitPoints MANUAL + } +} + +vertex_program PSSM/shadow_receiver_vsGLSLES glsles +{ + source pssmReceiverVp.glsles + profiles glsles + + default_params + { + param_named_auto lightPosition light_position_object_space 0 + param_named_auto eyePosition camera_position_object_space + param_named_auto worldViewProjMatrix worldviewproj_matrix + param_named_auto texWorldViewProjMatrix0 texture_worldviewproj_matrix 0 + param_named_auto texWorldViewProjMatrix1 texture_worldviewproj_matrix 1 + param_named_auto texWorldViewProjMatrix2 texture_worldviewproj_matrix 2 + //param_named_auto depthRange0 shadow_scene_depth_range 0 + //param_named_auto depthRange1 shadow_scene_depth_range 1 + //param_named_auto depthRange2 shadow_scene_depth_range 2 + } +} + +fragment_program PSSM/shadow_receiver_psGLSLES glsles +{ + source pssmReceiverFp.glsles + profiles glsles + + default_params + { + param_named_auto lightDiffuse derived_light_diffuse_colour 0 + param_named_auto lightSpecular derived_light_specular_colour 0 + param_named_auto ambient derived_ambient_light_colour + param_named_auto invShadowMapSize0 inverse_texture_size 0 + param_named_auto invShadowMapSize1 inverse_texture_size 1 + param_named_auto invShadowMapSize2 inverse_texture_size 2 + //param_named pssmSplitPoints MANUAL + } +} + +vertex_program PSSM/shadow_receiver_vs unified +{ + delegate PSSM/shadow_receiver_vsGLSLES + delegate PSSM/shadow_receiver_vsCg +} + +fragment_program PSSM/shadow_receiver_ps unified +{ + delegate PSSM/shadow_receiver_psGLSLES + delegate PSSM/shadow_receiver_psCg +} + +abstract material PSSM/base_receiver +{ + technique + { + pass + { + ambient 1 1 1 1 + diffuse 1 1 1 1 + + vertex_program_ref PSSM/shadow_receiver_vs {} + fragment_program_ref PSSM/shadow_receiver_ps {} + + texture_unit shadow_tex0 + { + content_type shadow + tex_address_mode clamp + } + texture_unit shadow_tex1 + { + content_type shadow + tex_address_mode clamp + } + texture_unit shadow_tex2 + { + content_type shadow + tex_address_mode clamp + } + + texture_unit diffuse_tex + { + texture $diffuse + } + } + } +} + +material PSSM/Plane : PSSM/base_receiver +{ + set $diffuse BumpyMetal.jpg +} + +material PSSM/Knot : PSSM/base_receiver +{ + set $diffuse MtlPlat2.jpg +} + diff --git a/res/dist/media/materials/scripts/shadows.material b/res/dist/media/materials/scripts/shadows.material new file mode 100644 index 00000000000..9f25ba4f0a4 --- /dev/null +++ b/res/dist/media/materials/scripts/shadows.material @@ -0,0 +1,130 @@ +// Template materials for integrated depth shadows + +vertex_program Ogre/shadow/caster/depth/vp cg +{ + source depthshadowobject.cg + profiles vs_1_1 arbvp1 + entry_point main_vp + compile_arguments -DSHADOWCASTER=1 -DDEPTH_SHADOWCASTER=1 -DDEPTH_SHADOWRECEIVER=0 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto depthRange scene_depth_range 0 + } +} + +fragment_program Ogre/shadow/caster/depth/fp cg +{ + source depthshadowobject.cg + profiles ps_2_x arbfp1 + entry_point main_fp + compile_arguments -DSHADOWCASTER=1 -DDEPTH_SHADOWCASTER=1 -DDEPTH_SHADOWRECEIVER=0 + + default_params + { + } +} + + + +vertex_program Ogre/shadow/receiver/depth/pssm3/vp cg +{ + source depthshadowobject.cg + profiles vs_1_1 arbvp1 + entry_point main_vp + compile_arguments -DSHADOWCASTER=0 -DDEPTH_SHADOWCASTER=0 -DDEPTH_SHADOWRECEIVER=1 + + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + param_named_auto lightPosition light_position_object_space 0 + param_named_auto lightDiffuse derived_light_diffuse_colour 0 + param_named_auto depthRange0 shadow_scene_depth_range 0 + param_named_auto depthRange1 shadow_scene_depth_range 1 + param_named_auto depthRange2 shadow_scene_depth_range 2 + + param_named_auto texWorldViewProjMatrix0 texture_worldviewproj_matrix 0 + param_named_auto texWorldViewProjMatrix1 texture_worldviewproj_matrix 1 + param_named_auto texWorldViewProjMatrix2 texture_worldviewproj_matrix 2 + } +} + +fragment_program Ogre/shadow/receiver/depth/pssm3/fp cg +{ + source depthshadowobject.cg + profiles ps_2_x arbfp1 + entry_point main_fp + compile_arguments -DSHADOWCASTER=0 -DDEPTH_SHADOWCASTER=0 -DDEPTH_SHADOWRECEIVER=1 + + default_params + { + param_named_auto materialAmbient derived_ambient_light_colour + // shadow samplers are indexes 1/2/3 + param_named_auto inverseShadowmapSize0 inverse_texture_size 1 + param_named_auto inverseShadowmapSize1 inverse_texture_size 2 + param_named_auto inverseShadowmapSize2 inverse_texture_size 3 + //SET THIS MANUALLY! + //param_named pssmSplitPoints 0 0 0 0 + } +} + +material Ogre/shadow/depth/caster +{ + technique + { + pass + { + vertex_program_ref Ogre/shadow/caster/depth/vp + { + } + fragment_program_ref Ogre/shadow/caster/depth/fp + { + } + } + } +} + +material Ogre/shadow/depth/integrated/pssm +{ + technique + { + // link to caster material + shadow_caster_material Ogre/shadow/depth/caster + + pass + { + vertex_program_ref Ogre/shadow/receiver/depth/pssm3/vp + { + } + fragment_program_ref Ogre/shadow/receiver/depth/pssm3/fp + { + // you must specify pssmSplitPoints when you instantiate! + } + + texture_unit diffuse + { + // nothing specified for now, derivers can override + } + + texture_unit shadow0 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + texture_unit shadow1 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + texture_unit shadow2 + { + content_type shadow + tex_address_mode border + tex_border_colour 1 1 1 1 + } + } + } +} diff --git a/res/dist/media/materials/scripts/sibenik.material b/res/dist/media/materials/scripts/sibenik.material new file mode 100644 index 00000000000..0f860c259cc --- /dev/null +++ b/res/dist/media/materials/scripts/sibenik.material @@ -0,0 +1,305 @@ + +material sibenik/Default +{ + technique + { + pass + { + ambient 0.698039 0.698039 0.698039 1 + diffuse 0.698039 0.698039 0.698039 1 + } + + } + +} + +material sibenik/poplocenje +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.65098 0.647059 0.596078 1 + + texture_unit + { + texture KAMEN320x240.jpg + } + } + + } + +} + +material sibenik/kuce +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.733333 0.729412 0.670588 1 + + texture_unit + { + texture KAMEN320x240.jpg + } + } + + } + +} + +material sibenik/staklo_zuto +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.498039 0.443137 0.00392157 1.19 + } + + } + +} + +material sibenik/kamen_zid_prozor +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.733333 0.729412 0.670588 1 + + texture_unit + { + texture KAMEN320x240.jpg + } + } + + } + +} + +material sibenik/pod-rub +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.733333 0.729412 0.670588 1 + + texture_unit + { + texture KAMEN320x240.jpg + } + } + + } + +} + +material sibenik/staklo_plavo +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.0392157 0.0705882 0.392157 1.19 + } + + } + +} + +material sibenik/staklo_crveno +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.439216 0.101961 0.0470588 1.19 + } + + } + +} + +material sibenik/sprljci +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.784314 0.784314 0.784314 1 + } + + } + +} + +material sibenik/staklo_zeleno +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.0313726 0.313726 0.0352941 1.19 + } + + } + +} + +material sibenik/rozeta +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.733333 0.729412 0.670588 1 + + texture_unit + { + texture KAMEN-stup.jpg + } + } + + } + +} + +material sibenik/kamen_zid_parape +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.733333 0.729412 0.670588 1 + + texture_unit + { + texture KAMEN-stup.jpg + } + } + + } + +} + +material sibenik/zid_vani +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.733333 0.729412 0.670588 1 + + texture_unit + { + texture KAMEN320x240.jpg + } + } + + } + +} + +material sibenik/glas +{ + technique + { + pass + { + ambient 0.639216 0.639216 0.639216 1 + diffuse 1 1 1 0.5 + scene_blend alpha_blend + depth_write off + } + + } + +} + +material sibenik/pod +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.733333 0.705882 0.670588 1 + + texture_unit + { + texture MRAMOR6X6.jpg + } + } + + } + +} + +material sibenik/pod_tepih +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.545098 0.219608 0.180392 1 + } + + } + +} + +material sibenik/stupovi +{ + technique + { + pass + { + ambient 0 0 0 1 + diffuse 0.733333 0.729412 0.670588 1 + + texture_unit + { + texture KAMEN-stup.jpg + } + } + + } + +} + +material sibenik/kamen_zid +{ + technique + { + pass + { + ambient 0.733333 0.729412 0.670588 1 + diffuse 0.733333 0.729412 0.670588 1 + cull_hardware none + + texture_unit + { + texture KAMEN320x240.jpg + } + } + + } + +} diff --git a/res/dist/media/materials/scripts/smoke.material b/res/dist/media/materials/scripts/smoke.material new file mode 100644 index 00000000000..3c4c9bbb689 --- /dev/null +++ b/res/dist/media/materials/scripts/smoke.material @@ -0,0 +1,19 @@ +material Examples/Smoke +{ + technique + { + pass + { + lighting off + scene_blend alpha_blend + depth_write off + diffuse vertexcolour + + texture_unit + { + texture smoke.png + tex_address_mode clamp + } + } + } +} \ No newline at end of file diff --git a/res/dist/media/materials/textures/10points.png b/res/dist/media/materials/textures/10points.png new file mode 100644 index 00000000000..a932146c273 Binary files /dev/null and b/res/dist/media/materials/textures/10points.png differ diff --git a/res/dist/media/materials/textures/1D_Noise.png b/res/dist/media/materials/textures/1D_Noise.png new file mode 100644 index 00000000000..d03ed1ee355 Binary files /dev/null and b/res/dist/media/materials/textures/1D_Noise.png differ diff --git a/res/dist/media/materials/textures/1D_Noise2.png b/res/dist/media/materials/textures/1D_Noise2.png new file mode 100644 index 00000000000..9dfd6f845a6 Binary files /dev/null and b/res/dist/media/materials/textures/1D_Noise2.png differ diff --git a/res/dist/media/materials/textures/1d_SPIRAL.png b/res/dist/media/materials/textures/1d_SPIRAL.png new file mode 100644 index 00000000000..505ba108893 Binary files /dev/null and b/res/dist/media/materials/textures/1d_SPIRAL.png differ diff --git a/res/dist/media/materials/textures/1d_debug.png b/res/dist/media/materials/textures/1d_debug.png new file mode 100644 index 00000000000..5664094e7ec Binary files /dev/null and b/res/dist/media/materials/textures/1d_debug.png differ diff --git a/res/dist/media/materials/textures/8x8PagesSplotches2.png b/res/dist/media/materials/textures/8x8PagesSplotches2.png new file mode 100644 index 00000000000..6a6b1051d86 Binary files /dev/null and b/res/dist/media/materials/textures/8x8PagesSplotches2.png differ diff --git a/res/dist/media/materials/textures/ASCII.dds b/res/dist/media/materials/textures/ASCII.dds new file mode 100644 index 00000000000..845f1bdcc74 Binary files /dev/null and b/res/dist/media/materials/textures/ASCII.dds differ diff --git a/res/dist/media/materials/textures/BeachStones.jpg b/res/dist/media/materials/textures/BeachStones.jpg new file mode 100644 index 00000000000..faaa16fe041 Binary files /dev/null and b/res/dist/media/materials/textures/BeachStones.jpg differ diff --git a/res/dist/media/materials/textures/BumpyMetal.jpg b/res/dist/media/materials/textures/BumpyMetal.jpg new file mode 100644 index 00000000000..146102fe205 Binary files /dev/null and b/res/dist/media/materials/textures/BumpyMetal.jpg differ diff --git a/res/dist/media/materials/textures/Chrome.jpg b/res/dist/media/materials/textures/Chrome.jpg new file mode 100644 index 00000000000..0ae5c526038 Binary files /dev/null and b/res/dist/media/materials/textures/Chrome.jpg differ diff --git a/res/dist/media/materials/textures/Dirt.jpg b/res/dist/media/materials/textures/Dirt.jpg new file mode 100644 index 00000000000..8b74a42f1a4 Binary files /dev/null and b/res/dist/media/materials/textures/Dirt.jpg differ diff --git a/res/dist/media/materials/textures/Dr_Bunsen_Head.jpg b/res/dist/media/materials/textures/Dr_Bunsen_Head.jpg new file mode 100644 index 00000000000..3ef969d7b0e Binary files /dev/null and b/res/dist/media/materials/textures/Dr_Bunsen_Head.jpg differ diff --git a/res/dist/media/materials/textures/GLX_icon.png b/res/dist/media/materials/textures/GLX_icon.png new file mode 100644 index 00000000000..a13699bedba Binary files /dev/null and b/res/dist/media/materials/textures/GLX_icon.png differ diff --git a/res/dist/media/materials/textures/GreenSkin.jpg b/res/dist/media/materials/textures/GreenSkin.jpg new file mode 100644 index 00000000000..35d55252f30 Binary files /dev/null and b/res/dist/media/materials/textures/GreenSkin.jpg differ diff --git a/res/dist/media/materials/textures/HeatLookup.tga b/res/dist/media/materials/textures/HeatLookup.tga new file mode 100644 index 00000000000..e45ec53efc8 Binary files /dev/null and b/res/dist/media/materials/textures/HeatLookup.tga differ diff --git a/res/dist/media/materials/textures/HeatNoise.tga b/res/dist/media/materials/textures/HeatNoise.tga new file mode 100644 index 00000000000..159e3620542 Binary files /dev/null and b/res/dist/media/materials/textures/HeatNoise.tga differ diff --git a/res/dist/media/materials/textures/KAMEN-stup.jpg b/res/dist/media/materials/textures/KAMEN-stup.jpg new file mode 100644 index 00000000000..ba307918013 Binary files /dev/null and b/res/dist/media/materials/textures/KAMEN-stup.jpg differ diff --git a/res/dist/media/materials/textures/KAMEN320x240-bump.jpg b/res/dist/media/materials/textures/KAMEN320x240-bump.jpg new file mode 100644 index 00000000000..525f8f8c107 Binary files /dev/null and b/res/dist/media/materials/textures/KAMEN320x240-bump.jpg differ diff --git a/res/dist/media/materials/textures/KAMEN320x240.jpg b/res/dist/media/materials/textures/KAMEN320x240.jpg new file mode 100644 index 00000000000..0524edec5f6 Binary files /dev/null and b/res/dist/media/materials/textures/KAMEN320x240.jpg differ diff --git a/res/dist/media/materials/textures/LowRes.png b/res/dist/media/materials/textures/LowRes.png new file mode 100644 index 00000000000..c89f9abffb0 Binary files /dev/null and b/res/dist/media/materials/textures/LowRes.png differ diff --git a/res/dist/media/materials/textures/MRAMOR-bump.jpg b/res/dist/media/materials/textures/MRAMOR-bump.jpg new file mode 100644 index 00000000000..c9692710d39 Binary files /dev/null and b/res/dist/media/materials/textures/MRAMOR-bump.jpg differ diff --git a/res/dist/media/materials/textures/MRAMOR6X6.jpg b/res/dist/media/materials/textures/MRAMOR6X6.jpg new file mode 100644 index 00000000000..f3f25ce13c0 Binary files /dev/null and b/res/dist/media/materials/textures/MRAMOR6X6.jpg differ diff --git a/res/dist/media/materials/textures/MtlPlat2.jpg b/res/dist/media/materials/textures/MtlPlat2.jpg new file mode 100644 index 00000000000..2a200183e41 Binary files /dev/null and b/res/dist/media/materials/textures/MtlPlat2.jpg differ diff --git a/res/dist/media/materials/textures/NMBalls.png b/res/dist/media/materials/textures/NMBalls.png new file mode 100644 index 00000000000..74f02e379a2 Binary files /dev/null and b/res/dist/media/materials/textures/NMBalls.png differ diff --git a/res/dist/media/materials/textures/NMBumpsOut.png b/res/dist/media/materials/textures/NMBumpsOut.png new file mode 100644 index 00000000000..b5ef61e54f3 Binary files /dev/null and b/res/dist/media/materials/textures/NMBumpsOut.png differ diff --git a/res/dist/media/materials/textures/NMHollyBumps.png b/res/dist/media/materials/textures/NMHollyBumps.png new file mode 100644 index 00000000000..ac91b020002 Binary files /dev/null and b/res/dist/media/materials/textures/NMHollyBumps.png differ diff --git a/res/dist/media/materials/textures/NMStripes.png b/res/dist/media/materials/textures/NMStripes.png new file mode 100644 index 00000000000..407816215b3 Binary files /dev/null and b/res/dist/media/materials/textures/NMStripes.png differ diff --git a/res/dist/media/materials/textures/NPRMetallic.tga b/res/dist/media/materials/textures/NPRMetallic.tga new file mode 100644 index 00000000000..6649a6fb61c Binary files /dev/null and b/res/dist/media/materials/textures/NPRMetallic.tga differ diff --git a/res/dist/media/materials/textures/NoiseVolume.dds b/res/dist/media/materials/textures/NoiseVolume.dds new file mode 100644 index 00000000000..bd8147d49fd Binary files /dev/null and b/res/dist/media/materials/textures/NoiseVolume.dds differ diff --git a/res/dist/media/materials/textures/Panels_Diffuse.png b/res/dist/media/materials/textures/Panels_Diffuse.png new file mode 100644 index 00000000000..15b242c4adc Binary files /dev/null and b/res/dist/media/materials/textures/Panels_Diffuse.png differ diff --git a/res/dist/media/materials/textures/Panels_Normal_Obj.png b/res/dist/media/materials/textures/Panels_Normal_Obj.png new file mode 100644 index 00000000000..cd02bba35c9 Binary files /dev/null and b/res/dist/media/materials/textures/Panels_Normal_Obj.png differ diff --git a/res/dist/media/materials/textures/Panels_Normal_Tangent.png b/res/dist/media/materials/textures/Panels_Normal_Tangent.png new file mode 100644 index 00000000000..5501cb11de1 Binary files /dev/null and b/res/dist/media/materials/textures/Panels_Normal_Tangent.png differ diff --git a/res/dist/media/materials/textures/Panels_reflection.png b/res/dist/media/materials/textures/Panels_reflection.png new file mode 100644 index 00000000000..d685d9bbaea Binary files /dev/null and b/res/dist/media/materials/textures/Panels_reflection.png differ diff --git a/res/dist/media/materials/textures/Panels_refmask.png b/res/dist/media/materials/textures/Panels_refmask.png new file mode 100644 index 00000000000..6c4eaabe110 Binary files /dev/null and b/res/dist/media/materials/textures/Panels_refmask.png differ diff --git a/res/dist/media/materials/textures/RZR-002.png b/res/dist/media/materials/textures/RZR-002.png new file mode 100644 index 00000000000..663eb05d914 Binary files /dev/null and b/res/dist/media/materials/textures/RZR-002.png differ diff --git a/res/dist/media/materials/textures/Random3D.dds b/res/dist/media/materials/textures/Random3D.dds new file mode 100644 index 00000000000..08b61959fa6 Binary files /dev/null and b/res/dist/media/materials/textures/Random3D.dds differ diff --git a/res/dist/media/materials/textures/RustedMetal.jpg b/res/dist/media/materials/textures/RustedMetal.jpg new file mode 100644 index 00000000000..070346d3225 Binary files /dev/null and b/res/dist/media/materials/textures/RustedMetal.jpg differ diff --git a/res/dist/media/materials/textures/RustyBarrel.png b/res/dist/media/materials/textures/RustyBarrel.png new file mode 100644 index 00000000000..8448a8e72d3 Binary files /dev/null and b/res/dist/media/materials/textures/RustyBarrel.png differ diff --git a/res/dist/media/materials/textures/RustySteel.jpg b/res/dist/media/materials/textures/RustySteel.jpg new file mode 100644 index 00000000000..a2d7b9dff11 Binary files /dev/null and b/res/dist/media/materials/textures/RustySteel.jpg differ diff --git a/res/dist/media/materials/textures/SSAO/4InterleavedKMeansDisk8x4.png b/res/dist/media/materials/textures/SSAO/4InterleavedKMeansDisk8x4.png new file mode 100644 index 00000000000..286e25e59ff Binary files /dev/null and b/res/dist/media/materials/textures/SSAO/4InterleavedKMeansDisk8x4.png differ diff --git a/res/dist/media/materials/textures/SSAO/gray256.png b/res/dist/media/materials/textures/SSAO/gray256.png new file mode 100644 index 00000000000..c6e0d179287 Binary files /dev/null and b/res/dist/media/materials/textures/SSAO/gray256.png differ diff --git a/res/dist/media/materials/textures/SSAO/importance4InterleavedSphereHemisphere8x4.png b/res/dist/media/materials/textures/SSAO/importance4InterleavedSphereHemisphere8x4.png new file mode 100644 index 00000000000..892160009d7 Binary files /dev/null and b/res/dist/media/materials/textures/SSAO/importance4InterleavedSphereHemisphere8x4.png differ diff --git a/res/dist/media/materials/textures/SSAO/rand1x32.png b/res/dist/media/materials/textures/SSAO/rand1x32.png new file mode 100644 index 00000000000..c3ff3cbc798 Binary files /dev/null and b/res/dist/media/materials/textures/SSAO/rand1x32.png differ diff --git a/res/dist/media/materials/textures/SSAO/randCosSinJitter4x4.png b/res/dist/media/materials/textures/SSAO/randCosSinJitter4x4.png new file mode 100644 index 00000000000..0f9d1514cd8 Binary files /dev/null and b/res/dist/media/materials/textures/SSAO/randCosSinJitter4x4.png differ diff --git a/res/dist/media/materials/textures/SSAO/regularSphereJittered4.png b/res/dist/media/materials/textures/SSAO/regularSphereJittered4.png new file mode 100644 index 00000000000..0a1f34f9f2c Binary files /dev/null and b/res/dist/media/materials/textures/SSAO/regularSphereJittered4.png differ diff --git a/res/dist/media/materials/textures/Sepia1D.tga b/res/dist/media/materials/textures/Sepia1D.tga new file mode 100644 index 00000000000..dcc42620428 Binary files /dev/null and b/res/dist/media/materials/textures/Sepia1D.tga differ diff --git a/res/dist/media/materials/textures/SmallLeaf_BP.png b/res/dist/media/materials/textures/SmallLeaf_BP.png new file mode 100644 index 00000000000..c8c49a7045f Binary files /dev/null and b/res/dist/media/materials/textures/SmallLeaf_BP.png differ diff --git a/res/dist/media/materials/textures/TextureAtlasSampleOrg0.png b/res/dist/media/materials/textures/TextureAtlasSampleOrg0.png new file mode 100644 index 00000000000..8a4fb9b313b Binary files /dev/null and b/res/dist/media/materials/textures/TextureAtlasSampleOrg0.png differ diff --git a/res/dist/media/materials/textures/TextureAtlasSampleWrap0.png b/res/dist/media/materials/textures/TextureAtlasSampleWrap0.png new file mode 100644 index 00000000000..223591fce76 Binary files /dev/null and b/res/dist/media/materials/textures/TextureAtlasSampleWrap0.png differ diff --git a/res/dist/media/materials/textures/Water01.jpg b/res/dist/media/materials/textures/Water01.jpg new file mode 100644 index 00000000000..f9c9b7feec5 Binary files /dev/null and b/res/dist/media/materials/textures/Water01.jpg differ diff --git a/res/dist/media/materials/textures/Water02.jpg b/res/dist/media/materials/textures/Water02.jpg new file mode 100644 index 00000000000..3efda7b6a88 Binary files /dev/null and b/res/dist/media/materials/textures/Water02.jpg differ diff --git a/res/dist/media/materials/textures/WaterNormal1.tga b/res/dist/media/materials/textures/WaterNormal1.tga new file mode 100644 index 00000000000..a9ca11b7ed0 Binary files /dev/null and b/res/dist/media/materials/textures/WaterNormal1.tga differ diff --git a/res/dist/media/materials/textures/WaterNormal2.tga b/res/dist/media/materials/textures/WaterNormal2.tga new file mode 100644 index 00000000000..771d1504192 Binary files /dev/null and b/res/dist/media/materials/textures/WaterNormal2.tga differ diff --git a/res/dist/media/materials/textures/WoodPallet.png b/res/dist/media/materials/textures/WoodPallet.png new file mode 100644 index 00000000000..7727d71a9bb Binary files /dev/null and b/res/dist/media/materials/textures/WoodPallet.png differ diff --git a/res/dist/media/materials/textures/atheneNormalMap.png b/res/dist/media/materials/textures/atheneNormalMap.png new file mode 100644 index 00000000000..00dbf15e2df Binary files /dev/null and b/res/dist/media/materials/textures/atheneNormalMap.png differ diff --git a/res/dist/media/materials/textures/aureola.png b/res/dist/media/materials/textures/aureola.png new file mode 100644 index 00000000000..757f593fe87 Binary files /dev/null and b/res/dist/media/materials/textures/aureola.png differ diff --git a/res/dist/media/materials/textures/basic_droplet.png b/res/dist/media/materials/textures/basic_droplet.png new file mode 100644 index 00000000000..27ca8e8affe Binary files /dev/null and b/res/dist/media/materials/textures/basic_droplet.png differ diff --git a/res/dist/media/materials/textures/blue_jaiqua.jpg b/res/dist/media/materials/textures/blue_jaiqua.jpg new file mode 100644 index 00000000000..6016e140993 Binary files /dev/null and b/res/dist/media/materials/textures/blue_jaiqua.jpg differ diff --git a/res/dist/media/materials/textures/cel_shading_diffuse.png b/res/dist/media/materials/textures/cel_shading_diffuse.png new file mode 100644 index 00000000000..9cd4efbbe83 Binary files /dev/null and b/res/dist/media/materials/textures/cel_shading_diffuse.png differ diff --git a/res/dist/media/materials/textures/cel_shading_edge.png b/res/dist/media/materials/textures/cel_shading_edge.png new file mode 100644 index 00000000000..9cc118ab9f2 Binary files /dev/null and b/res/dist/media/materials/textures/cel_shading_edge.png differ diff --git a/res/dist/media/materials/textures/cel_shading_specular.png b/res/dist/media/materials/textures/cel_shading_specular.png new file mode 100644 index 00000000000..9cc118ab9f2 Binary files /dev/null and b/res/dist/media/materials/textures/cel_shading_specular.png differ diff --git a/res/dist/media/materials/textures/checker.png b/res/dist/media/materials/textures/checker.png new file mode 100644 index 00000000000..288c0a0c3ac Binary files /dev/null and b/res/dist/media/materials/textures/checker.png differ diff --git a/res/dist/media/materials/textures/circuit.dds b/res/dist/media/materials/textures/circuit.dds new file mode 100644 index 00000000000..d249d384fa2 Binary files /dev/null and b/res/dist/media/materials/textures/circuit.dds differ diff --git a/res/dist/media/materials/textures/clouds.jpg b/res/dist/media/materials/textures/clouds.jpg new file mode 100644 index 00000000000..4db0f11e208 Binary files /dev/null and b/res/dist/media/materials/textures/clouds.jpg differ diff --git a/res/dist/media/materials/textures/cursor.png b/res/dist/media/materials/textures/cursor.png new file mode 100644 index 00000000000..3d1c756cf17 Binary files /dev/null and b/res/dist/media/materials/textures/cursor.png differ diff --git a/res/dist/media/materials/textures/dark_grid.png b/res/dist/media/materials/textures/dark_grid.png new file mode 100644 index 00000000000..3619f81c90d Binary files /dev/null and b/res/dist/media/materials/textures/dark_grid.png differ diff --git a/res/dist/media/materials/textures/dirt01.jpg b/res/dist/media/materials/textures/dirt01.jpg new file mode 100644 index 00000000000..7c7cc5eb3ac Binary files /dev/null and b/res/dist/media/materials/textures/dirt01.jpg differ diff --git a/res/dist/media/materials/textures/dkyellow.png b/res/dist/media/materials/textures/dkyellow.png new file mode 100644 index 00000000000..88c1d64790f Binary files /dev/null and b/res/dist/media/materials/textures/dkyellow.png differ diff --git a/res/dist/media/materials/textures/droplet.png b/res/dist/media/materials/textures/droplet.png new file mode 100644 index 00000000000..f1cfc4a804f Binary files /dev/null and b/res/dist/media/materials/textures/droplet.png differ diff --git a/res/dist/media/materials/textures/egyptrockyfull.jpg b/res/dist/media/materials/textures/egyptrockyfull.jpg new file mode 100644 index 00000000000..044ce9f1692 Binary files /dev/null and b/res/dist/media/materials/textures/egyptrockyfull.jpg differ diff --git a/res/dist/media/materials/textures/flare.png b/res/dist/media/materials/textures/flare.png new file mode 100644 index 00000000000..9f8a2a8414d Binary files /dev/null and b/res/dist/media/materials/textures/flare.png differ diff --git a/res/dist/media/materials/textures/flare_alpha.dds b/res/dist/media/materials/textures/flare_alpha.dds new file mode 100644 index 00000000000..c9a357ece16 Binary files /dev/null and b/res/dist/media/materials/textures/flare_alpha.dds differ diff --git a/res/dist/media/materials/textures/flaretrail.png b/res/dist/media/materials/textures/flaretrail.png new file mode 100644 index 00000000000..55812b2fb77 Binary files /dev/null and b/res/dist/media/materials/textures/flaretrail.png differ diff --git a/res/dist/media/materials/textures/frost.png b/res/dist/media/materials/textures/frost.png new file mode 100644 index 00000000000..22fb89c35f0 Binary files /dev/null and b/res/dist/media/materials/textures/frost.png differ diff --git a/res/dist/media/materials/textures/fw12b.jpg b/res/dist/media/materials/textures/fw12b.jpg new file mode 100644 index 00000000000..980060541bf Binary files /dev/null and b/res/dist/media/materials/textures/fw12b.jpg differ diff --git a/res/dist/media/materials/textures/gras_02.png b/res/dist/media/materials/textures/gras_02.png new file mode 100644 index 00000000000..1110724cdc5 Binary files /dev/null and b/res/dist/media/materials/textures/gras_02.png differ diff --git a/res/dist/media/materials/textures/grassWalpha.tga b/res/dist/media/materials/textures/grassWalpha.tga new file mode 100644 index 00000000000..09067221ada Binary files /dev/null and b/res/dist/media/materials/textures/grassWalpha.tga differ diff --git a/res/dist/media/materials/textures/grass_1024.jpg b/res/dist/media/materials/textures/grass_1024.jpg new file mode 100644 index 00000000000..e65691b3ade Binary files /dev/null and b/res/dist/media/materials/textures/grass_1024.jpg differ diff --git a/res/dist/media/materials/textures/img1.png b/res/dist/media/materials/textures/img1.png new file mode 100644 index 00000000000..e55c57d9b8d Binary files /dev/null and b/res/dist/media/materials/textures/img1.png differ diff --git a/res/dist/media/materials/textures/img2.png b/res/dist/media/materials/textures/img2.png new file mode 100644 index 00000000000..d5c7db1377b Binary files /dev/null and b/res/dist/media/materials/textures/img2.png differ diff --git a/res/dist/media/materials/textures/leaf.png b/res/dist/media/materials/textures/leaf.png new file mode 100644 index 00000000000..9309d71a7f3 Binary files /dev/null and b/res/dist/media/materials/textures/leaf.png differ diff --git a/res/dist/media/materials/textures/nm_bk.png b/res/dist/media/materials/textures/nm_bk.png new file mode 100644 index 00000000000..65998a439cd Binary files /dev/null and b/res/dist/media/materials/textures/nm_bk.png differ diff --git a/res/dist/media/materials/textures/nm_dn.png b/res/dist/media/materials/textures/nm_dn.png new file mode 100644 index 00000000000..2b50b027a8f Binary files /dev/null and b/res/dist/media/materials/textures/nm_dn.png differ diff --git a/res/dist/media/materials/textures/nm_fr.png b/res/dist/media/materials/textures/nm_fr.png new file mode 100644 index 00000000000..e1f90f39da6 Binary files /dev/null and b/res/dist/media/materials/textures/nm_fr.png differ diff --git a/res/dist/media/materials/textures/nm_lf.png b/res/dist/media/materials/textures/nm_lf.png new file mode 100644 index 00000000000..28606136a03 Binary files /dev/null and b/res/dist/media/materials/textures/nm_lf.png differ diff --git a/res/dist/media/materials/textures/nm_rt.png b/res/dist/media/materials/textures/nm_rt.png new file mode 100644 index 00000000000..9d0d57176b6 Binary files /dev/null and b/res/dist/media/materials/textures/nm_rt.png differ diff --git a/res/dist/media/materials/textures/nm_up.png b/res/dist/media/materials/textures/nm_up.png new file mode 100644 index 00000000000..959347ac781 Binary files /dev/null and b/res/dist/media/materials/textures/nm_up.png differ diff --git a/res/dist/media/materials/textures/normalNoiseColor.png b/res/dist/media/materials/textures/normalNoiseColor.png new file mode 100644 index 00000000000..fc5f77bf72f Binary files /dev/null and b/res/dist/media/materials/textures/normalNoiseColor.png differ diff --git a/res/dist/media/materials/textures/nskingr.jpg b/res/dist/media/materials/textures/nskingr.jpg new file mode 100644 index 00000000000..9397f5d91ad Binary files /dev/null and b/res/dist/media/materials/textures/nskingr.jpg differ diff --git a/res/dist/media/materials/textures/nvidia/TextureUsageAgreement.txt b/res/dist/media/materials/textures/nvidia/TextureUsageAgreement.txt new file mode 100644 index 00000000000..102d61930ce --- /dev/null +++ b/res/dist/media/materials/textures/nvidia/TextureUsageAgreement.txt @@ -0,0 +1,26 @@ +The original diffuse textures are from the NVIDIA texture library, with other maps generated from them by Steve Streeting. The following license applies to all textures. + +Single Product or Project Use of NVSDK-Art Imagery +THIS IS A LEGAL AGREEMENT (the "License Agreement") between you and NVIDIA, Inc. ("Company"). If you do not agree to all the terms and conditions of this License Agreement, immediately delete the NVSDK-Art Imagery from your hard disk. If you proceed to use any of the images (the "Images") contained therein, you thereby signify that you have agreed to all of the terms and conditions set forth below. + +You may not use, copy, display, modify or distribute the Images except in strict accordance with this License Agreement. Company hereby grants to you the following worldwide, non-exclusive, non-transferable, non-sublicensable license for the Term below, with respect to its rights in the Images: + +You may install the Images on an unlimited number of computers; provided that all such computers are physically located at your place of business located at a single specific street address (or its equivalent). You may use and access the Images only at that one location and only as follows: You may use, copy and modify the Images in the creation and presentation of videogames, animations and renderings; provided that you may neither: (a) separately publish, market, distribute, transfer, sell or sublicense all or any part of the Images except in derivative form from which the original, or a substantially similar version of the original Image can be extracted; (b) output the Images to a print format other than for collateral materials (such as sales literature and illustrations) which support your primary electronic use of the Images. Subject to the foregoing limitations, and the rights, you may copy and distribute your animations and renderings incorporating the Images. + +All other rights with respect to the Images and their use are reserved to Company. + +The Images are protected by United States copyright laws, international treaty provisions, and other laws. + +TERM. You may use the Images for incorporation in a single product or production, or for visualization purposes within a single project of duration not more than three years. + +INFRINGEMENT WARRANTY. NVIDIA warrants to you that, to the best of its knowledge, the digital data for the Images do not infringe the rights, including patent, copyright and trade secret rights, of any third party; provided, however, that NVIDIA makes no representation or warranties with respect to infringement of any third party's rights by any image or object depicted by such digital data. + +LIMITATION OF LIABILITY AND WARRANTIES. YOU ASSUME THE ENTIRE COST OF ANY DAMAGE, LOSSES OR EXPENSE RESULTING FROM YOUR USE OR EXPLOITATION OF THE IMAGES. YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE IMAGES TO ACHIEVE YOUR INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED FROM THE IMAGES. + +TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, COMPANY HEREBY DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT (except as provided in the section titled "Infringement Warranty" above), AND FITNESS FOR A PARTICULAR PURPOSE WITH RESPECT TO THE IMAGES AND ANY ACCOMPANYING SOFTWARE OR MATERIALS. + +This License Agreement is the entire agreement between you and Company with respect to the Images and supersedes any other communications or advertising, whether written or oral, with respect thereto. If any provision of this License Agreement is held invalid or unenforceable, the remainder shall continue in full force and effect, provided that, if any limitation on the grant to you of any right herein is held invalid or unenforceable, such right shall immediately terminate. + +No Warranty. THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA TO DEVELOPER HEREUNDER ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +Limitation of Liability. NVIDIA SHALL NOT BE LIABLE TO DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS. + diff --git a/res/dist/media/materials/textures/nvidia/dirt_grayrocky_diffusespecular.dds b/res/dist/media/materials/textures/nvidia/dirt_grayrocky_diffusespecular.dds new file mode 100644 index 00000000000..ef8e9e8e0ba Binary files /dev/null and b/res/dist/media/materials/textures/nvidia/dirt_grayrocky_diffusespecular.dds differ diff --git a/res/dist/media/materials/textures/nvidia/dirt_grayrocky_normalheight.dds b/res/dist/media/materials/textures/nvidia/dirt_grayrocky_normalheight.dds new file mode 100644 index 00000000000..6cf58fd4ba3 Binary files /dev/null and b/res/dist/media/materials/textures/nvidia/dirt_grayrocky_normalheight.dds differ diff --git a/res/dist/media/materials/textures/nvidia/grass_green-01_diffusespecular.dds b/res/dist/media/materials/textures/nvidia/grass_green-01_diffusespecular.dds new file mode 100644 index 00000000000..315d4ead00e Binary files /dev/null and b/res/dist/media/materials/textures/nvidia/grass_green-01_diffusespecular.dds differ diff --git a/res/dist/media/materials/textures/nvidia/grass_green-01_normalheight.dds b/res/dist/media/materials/textures/nvidia/grass_green-01_normalheight.dds new file mode 100644 index 00000000000..c9cd8228aa2 Binary files /dev/null and b/res/dist/media/materials/textures/nvidia/grass_green-01_normalheight.dds differ diff --git a/res/dist/media/materials/textures/nvidia/growth_weirdfungus-03_diffusespecular.dds b/res/dist/media/materials/textures/nvidia/growth_weirdfungus-03_diffusespecular.dds new file mode 100644 index 00000000000..5710cf9b77f Binary files /dev/null and b/res/dist/media/materials/textures/nvidia/growth_weirdfungus-03_diffusespecular.dds differ diff --git a/res/dist/media/materials/textures/nvidia/growth_weirdfungus-03_normalheight.dds b/res/dist/media/materials/textures/nvidia/growth_weirdfungus-03_normalheight.dds new file mode 100644 index 00000000000..b196c321339 Binary files /dev/null and b/res/dist/media/materials/textures/nvidia/growth_weirdfungus-03_normalheight.dds differ diff --git a/res/dist/media/materials/textures/ogreborder.png b/res/dist/media/materials/textures/ogreborder.png new file mode 100644 index 00000000000..9cc0d9da1c1 Binary files /dev/null and b/res/dist/media/materials/textures/ogreborder.png differ diff --git a/res/dist/media/materials/textures/ogreborderUp.png b/res/dist/media/materials/textures/ogreborderUp.png new file mode 100644 index 00000000000..d1ee4a6b6d5 Binary files /dev/null and b/res/dist/media/materials/textures/ogreborderUp.png differ diff --git a/res/dist/media/materials/textures/ogrebordercenter.png b/res/dist/media/materials/textures/ogrebordercenter.png new file mode 100644 index 00000000000..c62c02af7a7 Binary files /dev/null and b/res/dist/media/materials/textures/ogrebordercenter.png differ diff --git a/res/dist/media/materials/textures/ogregui.tga b/res/dist/media/materials/textures/ogregui.tga new file mode 100644 index 00000000000..74f5efdabd0 Binary files /dev/null and b/res/dist/media/materials/textures/ogregui.tga differ diff --git a/res/dist/media/materials/textures/ogrelogo-small.jpg b/res/dist/media/materials/textures/ogrelogo-small.jpg new file mode 100644 index 00000000000..9cee64742db Binary files /dev/null and b/res/dist/media/materials/textures/ogrelogo-small.jpg differ diff --git a/res/dist/media/materials/textures/ogrelogo.png b/res/dist/media/materials/textures/ogrelogo.png new file mode 100644 index 00000000000..1bc197551c9 Binary files /dev/null and b/res/dist/media/materials/textures/ogrelogo.png differ diff --git a/res/dist/media/materials/textures/particle.dds b/res/dist/media/materials/textures/particle.dds new file mode 100644 index 00000000000..8161803a824 Binary files /dev/null and b/res/dist/media/materials/textures/particle.dds differ diff --git a/res/dist/media/materials/textures/penguin.jpg b/res/dist/media/materials/textures/penguin.jpg new file mode 100644 index 00000000000..65e92487a02 Binary files /dev/null and b/res/dist/media/materials/textures/penguin.jpg differ diff --git a/res/dist/media/materials/textures/perlinvolume.dds b/res/dist/media/materials/textures/perlinvolume.dds new file mode 100644 index 00000000000..bd8147d49fd Binary files /dev/null and b/res/dist/media/materials/textures/perlinvolume.dds differ diff --git a/res/dist/media/materials/textures/r2skin.jpg b/res/dist/media/materials/textures/r2skin.jpg new file mode 100644 index 00000000000..3e83a1246c0 Binary files /dev/null and b/res/dist/media/materials/textures/r2skin.jpg differ diff --git a/res/dist/media/materials/textures/radial.png b/res/dist/media/materials/textures/radial.png new file mode 100644 index 00000000000..e44794221d6 Binary files /dev/null and b/res/dist/media/materials/textures/radial.png differ diff --git a/res/dist/media/materials/textures/random.png b/res/dist/media/materials/textures/random.png new file mode 100644 index 00000000000..292c801d265 Binary files /dev/null and b/res/dist/media/materials/textures/random.png differ diff --git a/res/dist/media/materials/textures/ribbonband.png b/res/dist/media/materials/textures/ribbonband.png new file mode 100644 index 00000000000..e6966640c0b Binary files /dev/null and b/res/dist/media/materials/textures/ribbonband.png differ diff --git a/res/dist/media/materials/textures/rockwall.tga b/res/dist/media/materials/textures/rockwall.tga new file mode 100644 index 00000000000..5703a03aa89 Binary files /dev/null and b/res/dist/media/materials/textures/rockwall.tga differ diff --git a/res/dist/media/materials/textures/rockwall_NH.tga b/res/dist/media/materials/textures/rockwall_NH.tga new file mode 100644 index 00000000000..12fa50bd801 Binary files /dev/null and b/res/dist/media/materials/textures/rockwall_NH.tga differ diff --git a/res/dist/media/materials/textures/scr-back.png b/res/dist/media/materials/textures/scr-back.png new file mode 100644 index 00000000000..05cf80124fd Binary files /dev/null and b/res/dist/media/materials/textures/scr-back.png differ diff --git a/res/dist/media/materials/textures/scr-down-p.png b/res/dist/media/materials/textures/scr-down-p.png new file mode 100644 index 00000000000..31b575ea4ae Binary files /dev/null and b/res/dist/media/materials/textures/scr-down-p.png differ diff --git a/res/dist/media/materials/textures/scr-down.png b/res/dist/media/materials/textures/scr-down.png new file mode 100644 index 00000000000..d52b5475630 Binary files /dev/null and b/res/dist/media/materials/textures/scr-down.png differ diff --git a/res/dist/media/materials/textures/scr-thumb.png b/res/dist/media/materials/textures/scr-thumb.png new file mode 100644 index 00000000000..8f05cc72d6b Binary files /dev/null and b/res/dist/media/materials/textures/scr-thumb.png differ diff --git a/res/dist/media/materials/textures/scr-up-p.png b/res/dist/media/materials/textures/scr-up-p.png new file mode 100644 index 00000000000..b9b45dcb89a Binary files /dev/null and b/res/dist/media/materials/textures/scr-up-p.png differ diff --git a/res/dist/media/materials/textures/scr-up.png b/res/dist/media/materials/textures/scr-up.png new file mode 100644 index 00000000000..1e0f9b46ae1 Binary files /dev/null and b/res/dist/media/materials/textures/scr-up.png differ diff --git a/res/dist/media/materials/textures/smoke.png b/res/dist/media/materials/textures/smoke.png new file mode 100644 index 00000000000..5672e487449 Binary files /dev/null and b/res/dist/media/materials/textures/smoke.png differ diff --git a/res/dist/media/materials/textures/smokecolors.png b/res/dist/media/materials/textures/smokecolors.png new file mode 100644 index 00000000000..72bc634d7af Binary files /dev/null and b/res/dist/media/materials/textures/smokecolors.png differ diff --git a/res/dist/media/materials/textures/snow_1024.jpg b/res/dist/media/materials/textures/snow_1024.jpg new file mode 100644 index 00000000000..56590af4f76 Binary files /dev/null and b/res/dist/media/materials/textures/snow_1024.jpg differ diff --git a/res/dist/media/materials/textures/spacesky.jpg b/res/dist/media/materials/textures/spacesky.jpg new file mode 100644 index 00000000000..34d89d6cc9e Binary files /dev/null and b/res/dist/media/materials/textures/spacesky.jpg differ diff --git a/res/dist/media/materials/textures/spheremap.png b/res/dist/media/materials/textures/spheremap.png new file mode 100644 index 00000000000..e6b91475024 Binary files /dev/null and b/res/dist/media/materials/textures/spheremap.png differ diff --git a/res/dist/media/materials/textures/spine_strips.dds b/res/dist/media/materials/textures/spine_strips.dds new file mode 100644 index 00000000000..51538caecf6 Binary files /dev/null and b/res/dist/media/materials/textures/spine_strips.dds differ diff --git a/res/dist/media/materials/textures/spotlight_image.png b/res/dist/media/materials/textures/spotlight_image.png new file mode 100644 index 00000000000..5719e81821e Binary files /dev/null and b/res/dist/media/materials/textures/spotlight_image.png differ diff --git a/res/dist/media/materials/textures/steelhead.png b/res/dist/media/materials/textures/steelhead.png new file mode 100644 index 00000000000..4c2ba37040c Binary files /dev/null and b/res/dist/media/materials/textures/steelhead.png differ diff --git a/res/dist/media/materials/textures/strugotine.jpg b/res/dist/media/materials/textures/strugotine.jpg new file mode 100644 index 00000000000..18020f98548 Binary files /dev/null and b/res/dist/media/materials/textures/strugotine.jpg differ diff --git a/res/dist/media/materials/textures/terr_dirt-grass.jpg b/res/dist/media/materials/textures/terr_dirt-grass.jpg new file mode 100644 index 00000000000..001bd3e7890 Binary files /dev/null and b/res/dist/media/materials/textures/terr_dirt-grass.jpg differ diff --git a/res/dist/media/materials/textures/terr_rock-dirt.jpg b/res/dist/media/materials/textures/terr_rock-dirt.jpg new file mode 100644 index 00000000000..6fda5c7c19e Binary files /dev/null and b/res/dist/media/materials/textures/terr_rock-dirt.jpg differ diff --git a/res/dist/media/materials/textures/terr_rock6.jpg b/res/dist/media/materials/textures/terr_rock6.jpg new file mode 100644 index 00000000000..3100ed7413a Binary files /dev/null and b/res/dist/media/materials/textures/terr_rock6.jpg differ diff --git a/res/dist/media/materials/textures/terrain.png b/res/dist/media/materials/textures/terrain.png new file mode 100644 index 00000000000..16e853fe50d Binary files /dev/null and b/res/dist/media/materials/textures/terrain.png differ diff --git a/res/dist/media/materials/textures/terrain_detail.jpg b/res/dist/media/materials/textures/terrain_detail.jpg new file mode 100644 index 00000000000..981e37e6f71 Binary files /dev/null and b/res/dist/media/materials/textures/terrain_detail.jpg differ diff --git a/res/dist/media/materials/textures/terrain_texture.jpg b/res/dist/media/materials/textures/terrain_texture.jpg new file mode 100644 index 00000000000..8d4fda5a54b Binary files /dev/null and b/res/dist/media/materials/textures/terrain_texture.jpg differ diff --git a/res/dist/media/materials/textures/texmap2.jpg b/res/dist/media/materials/textures/texmap2.jpg new file mode 100644 index 00000000000..8acc84d77cd Binary files /dev/null and b/res/dist/media/materials/textures/texmap2.jpg differ diff --git a/res/dist/media/materials/textures/tusk.jpg b/res/dist/media/materials/textures/tusk.jpg new file mode 100644 index 00000000000..b699a525fd4 Binary files /dev/null and b/res/dist/media/materials/textures/tusk.jpg differ diff --git a/res/dist/media/materials/textures/waveNM.png b/res/dist/media/materials/textures/waveNM.png new file mode 100644 index 00000000000..766e2e73398 Binary files /dev/null and b/res/dist/media/materials/textures/waveNM.png differ diff --git a/res/dist/media/materials/textures/waves2.dds b/res/dist/media/materials/textures/waves2.dds new file mode 100644 index 00000000000..c379886faec Binary files /dev/null and b/res/dist/media/materials/textures/waves2.dds differ diff --git a/res/dist/media/materials/textures/white.bmp b/res/dist/media/materials/textures/white.bmp new file mode 100644 index 00000000000..397b5bf8bfa Binary files /dev/null and b/res/dist/media/materials/textures/white.bmp differ diff --git a/res/dist/media/models/Barrel.mesh b/res/dist/media/models/Barrel.mesh new file mode 100644 index 00000000000..acf8a44c23b Binary files /dev/null and b/res/dist/media/models/Barrel.mesh differ diff --git a/res/dist/media/models/RZR-002.mesh b/res/dist/media/models/RZR-002.mesh new file mode 100644 index 00000000000..630b7513633 Binary files /dev/null and b/res/dist/media/models/RZR-002.mesh differ diff --git a/res/dist/media/models/ShaderSystem.mesh b/res/dist/media/models/ShaderSystem.mesh new file mode 100644 index 00000000000..74bb6cdae6e Binary files /dev/null and b/res/dist/media/models/ShaderSystem.mesh differ diff --git a/res/dist/media/models/WoodPallet.mesh b/res/dist/media/models/WoodPallet.mesh new file mode 100644 index 00000000000..290e2388cae Binary files /dev/null and b/res/dist/media/models/WoodPallet.mesh differ diff --git a/res/dist/media/models/athene.mesh b/res/dist/media/models/athene.mesh new file mode 100644 index 00000000000..603397fa8b8 Binary files /dev/null and b/res/dist/media/models/athene.mesh differ diff --git a/res/dist/media/models/column.mesh b/res/dist/media/models/column.mesh new file mode 100644 index 00000000000..8099a142fec Binary files /dev/null and b/res/dist/media/models/column.mesh differ diff --git a/res/dist/media/models/cornell.mesh b/res/dist/media/models/cornell.mesh new file mode 100644 index 00000000000..68f0cd8d330 Binary files /dev/null and b/res/dist/media/models/cornell.mesh differ diff --git a/res/dist/media/models/cube.mesh b/res/dist/media/models/cube.mesh new file mode 100644 index 00000000000..f8d22199f3c Binary files /dev/null and b/res/dist/media/models/cube.mesh differ diff --git a/res/dist/media/models/facial.mesh b/res/dist/media/models/facial.mesh new file mode 100644 index 00000000000..02c7f9cc4c6 Binary files /dev/null and b/res/dist/media/models/facial.mesh differ diff --git a/res/dist/media/models/fish.mesh b/res/dist/media/models/fish.mesh new file mode 100644 index 00000000000..e20f1644df9 Binary files /dev/null and b/res/dist/media/models/fish.mesh differ diff --git a/res/dist/media/models/fish.skeleton b/res/dist/media/models/fish.skeleton new file mode 100644 index 00000000000..7a970fda23e Binary files /dev/null and b/res/dist/media/models/fish.skeleton differ diff --git a/res/dist/media/models/geosphere4500.mesh b/res/dist/media/models/geosphere4500.mesh new file mode 100644 index 00000000000..6471493ad75 Binary files /dev/null and b/res/dist/media/models/geosphere4500.mesh differ diff --git a/res/dist/media/models/geosphere8000.mesh b/res/dist/media/models/geosphere8000.mesh new file mode 100644 index 00000000000..c5140997e8f Binary files /dev/null and b/res/dist/media/models/geosphere8000.mesh differ diff --git a/res/dist/media/models/jaiqua.mesh b/res/dist/media/models/jaiqua.mesh new file mode 100644 index 00000000000..54f803a2c11 Binary files /dev/null and b/res/dist/media/models/jaiqua.mesh differ diff --git a/res/dist/media/models/jaiqua.skeleton b/res/dist/media/models/jaiqua.skeleton new file mode 100644 index 00000000000..3d7622c5b5b Binary files /dev/null and b/res/dist/media/models/jaiqua.skeleton differ diff --git a/res/dist/media/models/knot.mesh b/res/dist/media/models/knot.mesh new file mode 100644 index 00000000000..c699d45386c Binary files /dev/null and b/res/dist/media/models/knot.mesh differ diff --git a/res/dist/media/models/ninja.mesh b/res/dist/media/models/ninja.mesh new file mode 100644 index 00000000000..0032c55896d Binary files /dev/null and b/res/dist/media/models/ninja.mesh differ diff --git a/res/dist/media/models/ninja.skeleton b/res/dist/media/models/ninja.skeleton new file mode 100644 index 00000000000..787f5f753cb Binary files /dev/null and b/res/dist/media/models/ninja.skeleton differ diff --git a/res/dist/media/models/ogrehead.mesh b/res/dist/media/models/ogrehead.mesh new file mode 100644 index 00000000000..d36bf149da0 Binary files /dev/null and b/res/dist/media/models/ogrehead.mesh differ diff --git a/res/dist/media/models/penguin.mesh b/res/dist/media/models/penguin.mesh new file mode 100644 index 00000000000..bde4f541cf7 Binary files /dev/null and b/res/dist/media/models/penguin.mesh differ diff --git a/res/dist/media/models/penguin.skeleton b/res/dist/media/models/penguin.skeleton new file mode 100644 index 00000000000..105557bb3f2 Binary files /dev/null and b/res/dist/media/models/penguin.skeleton differ diff --git a/res/dist/media/models/razor.mesh b/res/dist/media/models/razor.mesh new file mode 100644 index 00000000000..da4f9c8a8ad Binary files /dev/null and b/res/dist/media/models/razor.mesh differ diff --git a/res/dist/media/models/robot.mesh b/res/dist/media/models/robot.mesh new file mode 100644 index 00000000000..16cadcf89ce Binary files /dev/null and b/res/dist/media/models/robot.mesh differ diff --git a/res/dist/media/models/robot.skeleton b/res/dist/media/models/robot.skeleton new file mode 100644 index 00000000000..0aa8bde5381 Binary files /dev/null and b/res/dist/media/models/robot.skeleton differ diff --git a/res/dist/media/models/sibenik.mesh b/res/dist/media/models/sibenik.mesh new file mode 100644 index 00000000000..5d7046ead47 Binary files /dev/null and b/res/dist/media/models/sibenik.mesh differ diff --git a/res/dist/media/models/sphere.mesh b/res/dist/media/models/sphere.mesh new file mode 100644 index 00000000000..89a806a6033 Binary files /dev/null and b/res/dist/media/models/sphere.mesh differ diff --git a/res/dist/media/models/spine.mesh b/res/dist/media/models/spine.mesh new file mode 100644 index 00000000000..5ffaeaa4810 Binary files /dev/null and b/res/dist/media/models/spine.mesh differ diff --git a/res/dist/media/models/spine.mesh.skeleton b/res/dist/media/models/spine.mesh.skeleton new file mode 100644 index 00000000000..66a5f4a9d69 Binary files /dev/null and b/res/dist/media/models/spine.mesh.skeleton differ diff --git a/res/dist/media/models/tudorhouse.mesh b/res/dist/media/models/tudorhouse.mesh new file mode 100644 index 00000000000..d940212c870 Binary files /dev/null and b/res/dist/media/models/tudorhouse.mesh differ diff --git a/res/dist/media/packs/SdkTrays.zip b/res/dist/media/packs/SdkTrays.zip new file mode 100644 index 00000000000..68ed40d2e68 Binary files /dev/null and b/res/dist/media/packs/SdkTrays.zip differ diff --git a/res/dist/media/packs/Sinbad.zip b/res/dist/media/packs/Sinbad.zip new file mode 100644 index 00000000000..ef007dfc270 Binary files /dev/null and b/res/dist/media/packs/Sinbad.zip differ diff --git a/res/dist/media/packs/chiropteraDM.pk3 b/res/dist/media/packs/chiropteraDM.pk3 new file mode 100644 index 00000000000..ffa2c6d385d Binary files /dev/null and b/res/dist/media/packs/chiropteraDM.pk3 differ diff --git a/res/dist/media/packs/chiropteraDM.txt b/res/dist/media/packs/chiropteraDM.txt new file mode 100644 index 00000000000..caa7829bb64 --- /dev/null +++ b/res/dist/media/packs/chiropteraDM.txt @@ -0,0 +1,99 @@ +date: September 17th 2001. +Quake3Arena DM level. + +==================================================== +title: ChiropteraDM +file: ChiropteraDM.pk3 + +authors: Alcatraz / Nunuk / Sock + +Alcatraz alcatraz@planetquake.com + http://www.planetquake.com/bighouse +Nunuk: nunuk@planetquake.com + http://www.planetquake.com/nunuk +Sock: sock@planetquake.com + http://www.planetquake.com/simland +==================================================== +Components + +Architecture: Nunuk +Gameplay: Alcatraz +Textures: Sock / Arnaud "pikouze" barros / Nunuk + +==================================================== +Play information + +tourney: yes +deathmatch: 2-6 +Bot File (aas): yes (Optimized) + +how to play place chiropteraDM.pk3 in your + /Quake III Arena/baseq3/ folder + start quake3 Arena + hit ~ + type /map chiropteraDM + type /addbot + hit ~ (to clear the console) + +Note: If the map does not start automatically after loading then make +sure you have the SV_PURE variable set to 0. I also included an arena +file in the pk3 file so that it can be loaded from the menus. + +==================================================== +Construction + +editor: Q3Radiant 197 by Id Software +build time: Original Map : 3 months, New version : 1 month +build version: 6(F) + +==================================================== +New Beta testers: Nunuk, Ttimo, NakedApe, Shallow[BAP] + +Thanks from Sock: + + Ttimo : for advice and testing. + NakedApe : for advice on TA items and testing. + alcatraz : for taking time on the level, and for his item placement. + Zed the best gf ever :P + +Additional thanks from Nunuk: + + my wife lorene. for her patience. + my son arthur.(stop slapping dad's keyboard!) + for advice and testing : nanospawn, bal, sock, shod, ttimo, spog. + auhsan - for inspiration :o) + th - too bad for the title, it will be for the next map. + just for being there : lunaran, grindspire, friction, and all at TF. + cool_ber - for being cool :> + ptit benj - always there for cool advices + bengal - for his awesome artwork + pappy-r, will, ash, and staff, @ planetquake + all the guys at qmap and terrafusion + ohz, shod and fff - for pimping and for always reminding me that i'll + become a real mapper when i'll stop doing these crappy space maps .... :oD + www.quakexpert.com + darkworks + yan "la crampe" - the only "dm17sucks" dude that passes at + least one hour a day playing in it. + arnaud "pikouse" - for allowing me to modify his own texes. + roland "poz_kak" + + +Thanx to all the other people that i could have forgot. ;) + +==================================================== +Distribution / Copyright / Permissions + +Copyright (c) 2001 sock, sock@planetquake.com +All rights reserved. + +Quake III Arena is a registered trademark of +id Software, Inc. + +This level may be electronically distributed only at +NO CHARGE to the recipient in its current state, MUST +include this .txt file, and may NOT be modified IN +ANY WAY. UNDER NO CIRCUMSTANCES IS THIS LEVEL TO BE +DISTRIBUTED ON CD-ROM WITHOUT PRIOR WRITTEN PERMISSION. + +==================================================== diff --git a/res/dist/media/packs/cubemap.zip b/res/dist/media/packs/cubemap.zip new file mode 100644 index 00000000000..899170190bb Binary files /dev/null and b/res/dist/media/packs/cubemap.zip differ diff --git a/res/dist/media/packs/cubemapsJS.zip b/res/dist/media/packs/cubemapsJS.zip new file mode 100644 index 00000000000..2309d0a09d1 Binary files /dev/null and b/res/dist/media/packs/cubemapsJS.zip differ diff --git a/res/dist/media/packs/dragon.zip b/res/dist/media/packs/dragon.zip new file mode 100644 index 00000000000..8a85791795c Binary files /dev/null and b/res/dist/media/packs/dragon.zip differ diff --git a/res/dist/media/packs/fresneldemo.zip b/res/dist/media/packs/fresneldemo.zip new file mode 100644 index 00000000000..48825851626 Binary files /dev/null and b/res/dist/media/packs/fresneldemo.zip differ diff --git a/res/dist/media/packs/ogredance.zip b/res/dist/media/packs/ogredance.zip new file mode 100644 index 00000000000..e34ace08799 Binary files /dev/null and b/res/dist/media/packs/ogredance.zip differ diff --git a/res/dist/media/packs/ogretestmap.zip b/res/dist/media/packs/ogretestmap.zip new file mode 100644 index 00000000000..63fb78609ec Binary files /dev/null and b/res/dist/media/packs/ogretestmap.zip differ diff --git a/res/dist/media/packs/profiler.zip b/res/dist/media/packs/profiler.zip new file mode 100644 index 00000000000..c73abd3f82d Binary files /dev/null and b/res/dist/media/packs/profiler.zip differ diff --git a/res/dist/media/packs/skybox.zip b/res/dist/media/packs/skybox.zip new file mode 100644 index 00000000000..06f6820d6b1 Binary files /dev/null and b/res/dist/media/packs/skybox.zip differ diff --git a/res/dist/media/particle/Examples-Water.particle b/res/dist/media/particle/Examples-Water.particle new file mode 100644 index 00000000000..658e722362e --- /dev/null +++ b/res/dist/media/particle/Examples-Water.particle @@ -0,0 +1,35 @@ +particle_system Examples/Water/Rain +{ + material Examples/Droplet + particle_width 100 + particle_height 300 + cull_each true + quota 100 + // Make common direction straight down (faster than self oriented) + billboard_type oriented_common + common_direction 0 -1 0 + + // Area emitter + emitter Box + { + angle 0 + emission_rate 20 + time_to_live 5 + direction 0 -1 0 + velocity 1000 + colour_range_start 0.3 1 0.3 + colour_range_end 0.7 1 0.7 + width 3000 + height 3000 + depth 0 + } + + // Gravity + affector LinearForce + { + force_vector 0 -1000 0 + force_application add + } + +} + diff --git a/res/dist/media/particle/Examples.particle b/res/dist/media/particle/Examples.particle new file mode 100644 index 00000000000..e5644605a7f --- /dev/null +++ b/res/dist/media/particle/Examples.particle @@ -0,0 +1,381 @@ +// Example particle systems + +// Exudes greeny particles which float upwards +particle_system Examples/GreenyNimbus +{ + material Examples/FlarePointSprite + particle_width 35 + particle_height 35 + cull_each false + cull_each false + quota 5000 + billboard_type point + + // Area emitter + emitter Box + { + angle 30 + emission_rate 30 + time_to_live 1 + direction 0 1 0 + velocity 0 + colour_range_start 1 1 0 + colour_range_end 0.3 1 0.3 + width 60 + height 60 + depth 60 + } + + // Make em float upwards + affector LinearForce + { + force_vector 0 100 0 + force_application add + } + + // Fader + affector ColourFader + { + red -0.25 + green -0.25 + blue -0.25 + } +} + +// A sparkly purple fountain +particle_system Examples/PurpleFountain +{ + material Examples/Flare2 + particle_width 20 + particle_height 40 + cull_each false + quota 10000 + billboard_type oriented_self + + // Area emitter + emitter Point + { + angle 15 + emission_rate 75 + time_to_live 3 + direction 0 1 0 + velocity_min 250 + velocity_max 300 + colour_range_start 0 0 0 + colour_range_end 1 1 1 + } + + // Gravity + affector LinearForce + { + force_vector 0 -100 0 + force_application add + } + + // Fader + affector ColourFader + { + red -0.25 + green -0.25 + blue -0.25 + } +} + + +// A downpour +particle_system Examples/Rain +{ + material Examples/Droplet + particle_width 20 + particle_height 100 + cull_each true + quota 10000 + // Make common direction straight down (faster than self oriented) + billboard_type oriented_common + common_direction 0 -1 0 + + // Area emitter + emitter Box + { + angle 0 + emission_rate 100 + time_to_live 5 + direction 0 -1 0 + velocity 50 + width 1000 + height 1000 + depth 0 + } + + // Gravity + affector LinearForce + { + force_vector 0 -200 0 + force_application add + } + +} + +// A jet engine (of sorts) +particle_system Examples/JetEngine1 +{ + material Examples/Flare + particle_width 25 + particle_height 25 + cull_each false + quota 200 + billboard_type point + + emitter Point + { + angle 5 + emission_rate 100 + time_to_live 1 + direction 0 -1 0 + velocity_min 250 + velocity_max 300 + colour_range_start 1 1 0.5 + colour_range_end 1 0.8 0.3 + + } + affector ColourFader + { + red -0.25 + green -1 + blue -1 + } + +} +particle_system Examples/JetEngine2 +{ + material Examples/Flare + particle_width 15 + particle_height 15 + cull_each false + quota 200 + billboard_type point + + emitter Point + { + angle 3 + emission_rate 100 + time_to_live 1 + direction 0 -1 0 + velocity_min 350 + velocity_max 400 + colour_range_start 0.5 1 1 + colour_range_end 0.3 0.8 1 + + } + affector ColourFader + { + red -1 + green -1 + blue -0.5 + } + +} + +// Exudes aureola particles which around the model float upwards +particle_system Examples/Aureola +{ + material Examples/Aureola + particle_width 200 + particle_height 200 + cull_each false + quota 100 + billboard_type perpendicular_common + common_direction 0 1 0 + common_up_vector 0 0 1 + + // Area emitter + emitter Box + { + angle 30 + emission_rate 4 + time_to_live 5 + position 0 -100 0 + direction 0 1 0 + velocity_min 0 + velocity_max 30 + colour_range_start 0.3 0.3 0.3 0.0 + colour_range_end 0.8 0.8 0.8 0.0 + width 10 + height 10 + depth 30 + } + + // Make em float upwards + affector LinearForce + { + force_vector 0 70 0 + force_application add + } + + // Fader + affector ColourFader2 + { + red1 +0.4 + green1 +0.4 + blue1 +0.4 + alpha1 +0.7 + + red2 -0.25 + green2 -0.25 + blue2 -0.25 + alpha2 -0.3333 + + state_change 3.5 + } + + // Rotater + affector Rotator + { + rotation_range_start 0 + rotation_range_end 360 + rotation_speed_range_start 0 + rotation_speed_range_end 360 + } +} + + +particle_system Examples/Swarm +{ + quota 3000 + material Examples/Flare2 + particle_width 12 + particle_height 24 + cull_each true + renderer billboard + sorted true + local_space false + billboard_type oriented_self + + emitter Box + { + angle 180 + colour 1 1 1 1 + colour_range_start 1 1 1 1 + colour_range_end 1 1 1 1 + direction 0 1 0 + emission_rate 30 + position 0 0 0 + velocity 50 + velocity_min 50 + velocity_max 1 + time_to_live 20 + time_to_live_min 20 + time_to_live_max 20 + duration 0 + duration_min 0 + duration_max 0 + repeat_delay 0 + repeat_delay_min 0 + repeat_delay_max 0 + width 80 + height 80 + depth 80 + } + + affector ColourFader + { + red -0.05 + green 0 + blue 0 + alpha 0 + } + + affector DeflectorPlane + { + plane_point 0 -50 0 + plane_normal 0 1 0 + bounce 1 + } + + affector DeflectorPlane + { + plane_point 0 50 0 + plane_normal 0 -1 0 + bounce 1 + } + + affector DeflectorPlane + { + plane_point 50 0 0 + plane_normal -1 0 0 + bounce 1 + } + + affector DeflectorPlane + { + plane_point -50 0 0 + plane_normal 1 0 0 + bounce 1 + } + + affector DeflectorPlane + { + plane_point 0 0 50 + plane_normal 0 0 -1 + bounce 1 + } + + affector DeflectorPlane + { + plane_point 0 0 -50 + plane_normal 0 0 1 + bounce 1 + } + + affector DirectionRandomiser + { + randomness 60 + } +} + + +particle_system Examples/Snow +{ + quota 2000 + material Examples/Flare + particle_width 4 + particle_height 4 + cull_each true + renderer billboard + sorted true + local_space false + billboard_type point + + emitter Box + { + angle 0 + colour 1 1 1 1 + colour_range_start 1 1 1 1 + colour_range_end 1 1 1 1 + direction 0 -1 0 + emission_rate 100 + position 0 200 0 + velocity 20 + velocity_min 20 + velocity_max 20 + time_to_live 20 + time_to_live_min 20 + time_to_live_max 20 + duration 0 + duration_min 0 + duration_max 0 + repeat_delay 0 + repeat_delay_min 0 + repeat_delay_max 0 + width 200 + height 200 + depth 1 + } + + affector DirectionRandomiser + { + randomness 10 + } +} + + diff --git a/res/dist/media/particle/emitted_emitter.particle b/res/dist/media/particle/emitted_emitter.particle new file mode 100644 index 00000000000..195c6130bc4 --- /dev/null +++ b/res/dist/media/particle/emitted_emitter.particle @@ -0,0 +1,56 @@ +// Example emitted emitters +particle_system Examples/Fireworks +{ + material Examples/Flare + point_rendering false + particle_width 10 + particle_height 10 + cull_each false + quota 1000 + emit_emitter_quota 10 + billboard_type point + + // Emitter that emits multiple Point emitters with name 'explosion' + emitter Box + { + name mainEmitter + emit_emitter explosion + angle 30 + emission_rate 1000 + time_to_live 3 + direction 0 1 0 + velocity 200 + } + + // This Point emitter is emitted by the Box emitter and emits billboard particles itself + emitter Point + { + name explosion + angle 180 + emission_rate 1000 + time_to_live 2 + direction 0 1 0 + velocity 80 + duration 0.1 + repeat_delay_min 2 + repeat_delay_max 3 + } + + // Make em float downwards + affector LinearForce + { + force_vector 0 -100 0 + force_application add + } + + // Give em some nice colours + affector ColourInterpolator + { + time0 0 + colour0 1 1 0 + time1 0.5 + colour1 1 0 0 + time2 0.9 + colour2 0 0 1 + } +} diff --git a/res/dist/media/particle/smoke.particle b/res/dist/media/particle/smoke.particle new file mode 100644 index 00000000000..13de9b960c9 --- /dev/null +++ b/res/dist/media/particle/smoke.particle @@ -0,0 +1,44 @@ +// Example particle systems + +// smoke +particle_system Examples/Smoke +{ + material Examples/Smoke + particle_width 35 + particle_height 35 + cull_each true + quota 500 + billboard_type point + sorted true + + // Area emitter + emitter Point + { + position 0 15 -15 + angle 35 + emission_rate 15 + time_to_live 4 + direction 0 1 0 + velocity_min 50 + velocity_max 80 + } + + affector ColourImage + { + image smokecolors.png + } + + affector Rotator + { + rotation_range_start 0 + rotation_range_end 360 + rotation_speed_range_start -60 + rotation_speed_range_end 200 + } + + affector Scaler + { + rate 50 + } + +} diff --git a/res/dist/media/terrain.cfg b/res/dist/media/terrain.cfg new file mode 100644 index 00000000000..5d69f11265b --- /dev/null +++ b/res/dist/media/terrain.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=terrain.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=100 + +# 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/thumbnails/thumb_bezier.png b/res/dist/media/thumbnails/thumb_bezier.png new file mode 100644 index 00000000000..18e95b88ba1 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_bezier.png differ diff --git a/res/dist/media/thumbnails/thumb_bsp.png b/res/dist/media/thumbnails/thumb_bsp.png new file mode 100644 index 00000000000..bf4eab7cf86 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_bsp.png differ diff --git a/res/dist/media/thumbnails/thumb_bump.png b/res/dist/media/thumbnails/thumb_bump.png new file mode 100644 index 00000000000..9a6a36eaba6 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_bump.png differ diff --git a/res/dist/media/thumbnails/thumb_camtrack.png b/res/dist/media/thumbnails/thumb_camtrack.png new file mode 100644 index 00000000000..10cbf7a59bc Binary files /dev/null and b/res/dist/media/thumbnails/thumb_camtrack.png differ diff --git a/res/dist/media/thumbnails/thumb_cel.png b/res/dist/media/thumbnails/thumb_cel.png new file mode 100644 index 00000000000..899ec4a2d99 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_cel.png differ diff --git a/res/dist/media/thumbnails/thumb_char.png b/res/dist/media/thumbnails/thumb_char.png new file mode 100644 index 00000000000..800d93a3384 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_char.png differ diff --git a/res/dist/media/thumbnails/thumb_comp.png b/res/dist/media/thumbnails/thumb_comp.png new file mode 100644 index 00000000000..c1b77105afb Binary files /dev/null and b/res/dist/media/thumbnails/thumb_comp.png differ diff --git a/res/dist/media/thumbnails/thumb_cubemap.png b/res/dist/media/thumbnails/thumb_cubemap.png new file mode 100644 index 00000000000..f82e2129c41 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_cubemap.png differ diff --git a/res/dist/media/thumbnails/thumb_deferred.png b/res/dist/media/thumbnails/thumb_deferred.png new file mode 100644 index 00000000000..55a3c24c3ec Binary files /dev/null and b/res/dist/media/thumbnails/thumb_deferred.png differ diff --git a/res/dist/media/thumbnails/thumb_dualquaternionskinning.png b/res/dist/media/thumbnails/thumb_dualquaternionskinning.png new file mode 100644 index 00000000000..89b34bad134 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_dualquaternionskinning.png differ diff --git a/res/dist/media/thumbnails/thumb_dyntex.png b/res/dist/media/thumbnails/thumb_dyntex.png new file mode 100644 index 00000000000..12deac38620 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_dyntex.png differ diff --git a/res/dist/media/thumbnails/thumb_error.png b/res/dist/media/thumbnails/thumb_error.png new file mode 100644 index 00000000000..056d139775d Binary files /dev/null and b/res/dist/media/thumbnails/thumb_error.png differ diff --git a/res/dist/media/thumbnails/thumb_facial.png b/res/dist/media/thumbnails/thumb_facial.png new file mode 100644 index 00000000000..173bf732df5 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_facial.png differ diff --git a/res/dist/media/thumbnails/thumb_fresnel.png b/res/dist/media/thumbnails/thumb_fresnel.png new file mode 100644 index 00000000000..d1030625898 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_fresnel.png differ diff --git a/res/dist/media/thumbnails/thumb_grass.png b/res/dist/media/thumbnails/thumb_grass.png new file mode 100644 index 00000000000..431de625749 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_grass.png differ diff --git a/res/dist/media/thumbnails/thumb_instancing.png b/res/dist/media/thumbnails/thumb_instancing.png new file mode 100644 index 00000000000..2c02d99001a Binary files /dev/null and b/res/dist/media/thumbnails/thumb_instancing.png differ diff --git a/res/dist/media/thumbnails/thumb_isosurf.png b/res/dist/media/thumbnails/thumb_isosurf.png new file mode 100644 index 00000000000..1399f6c2835 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_isosurf.png differ diff --git a/res/dist/media/thumbnails/thumb_lighting.png b/res/dist/media/thumbnails/thumb_lighting.png new file mode 100644 index 00000000000..5d6db48ae8e Binary files /dev/null and b/res/dist/media/thumbnails/thumb_lighting.png differ diff --git a/res/dist/media/thumbnails/thumb_newinstancing.png b/res/dist/media/thumbnails/thumb_newinstancing.png new file mode 100644 index 00000000000..680e0742d1b Binary files /dev/null and b/res/dist/media/thumbnails/thumb_newinstancing.png differ diff --git a/res/dist/media/thumbnails/thumb_ocean.png b/res/dist/media/thumbnails/thumb_ocean.png new file mode 100644 index 00000000000..f035d52cd9f Binary files /dev/null and b/res/dist/media/thumbnails/thumb_ocean.png differ diff --git a/res/dist/media/thumbnails/thumb_particlegs.png b/res/dist/media/thumbnails/thumb_particlegs.png new file mode 100644 index 00000000000..c52a50b6b89 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_particlegs.png differ diff --git a/res/dist/media/thumbnails/thumb_particles.png b/res/dist/media/thumbnails/thumb_particles.png new file mode 100644 index 00000000000..f7c1f424ce8 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_particles.png differ diff --git a/res/dist/media/thumbnails/thumb_playpen.png b/res/dist/media/thumbnails/thumb_playpen.png new file mode 100644 index 00000000000..5157584a5e7 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_playpen.png differ diff --git a/res/dist/media/thumbnails/thumb_shadersystem.png b/res/dist/media/thumbnails/thumb_shadersystem.png new file mode 100644 index 00000000000..05e25f8bd3e Binary files /dev/null and b/res/dist/media/thumbnails/thumb_shadersystem.png differ diff --git a/res/dist/media/thumbnails/thumb_shadows.png b/res/dist/media/thumbnails/thumb_shadows.png new file mode 100644 index 00000000000..2443721dd4d Binary files /dev/null and b/res/dist/media/thumbnails/thumb_shadows.png differ diff --git a/res/dist/media/thumbnails/thumb_skelanim.png b/res/dist/media/thumbnails/thumb_skelanim.png new file mode 100644 index 00000000000..d72ff5d48ae Binary files /dev/null and b/res/dist/media/thumbnails/thumb_skelanim.png differ diff --git a/res/dist/media/thumbnails/thumb_skybox.png b/res/dist/media/thumbnails/thumb_skybox.png new file mode 100644 index 00000000000..0aba3efa9fc Binary files /dev/null and b/res/dist/media/thumbnails/thumb_skybox.png differ diff --git a/res/dist/media/thumbnails/thumb_skydome.png b/res/dist/media/thumbnails/thumb_skydome.png new file mode 100644 index 00000000000..3b0ec022954 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_skydome.png differ diff --git a/res/dist/media/thumbnails/thumb_skyplane.png b/res/dist/media/thumbnails/thumb_skyplane.png new file mode 100644 index 00000000000..5ff249ce753 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_skyplane.png differ diff --git a/res/dist/media/thumbnails/thumb_smoke.png b/res/dist/media/thumbnails/thumb_smoke.png new file mode 100644 index 00000000000..78417c9b829 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_smoke.png differ diff --git a/res/dist/media/thumbnails/thumb_spheremap.png b/res/dist/media/thumbnails/thumb_spheremap.png new file mode 100644 index 00000000000..4156349e635 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_spheremap.png differ diff --git a/res/dist/media/thumbnails/thumb_ssao.png b/res/dist/media/thumbnails/thumb_ssao.png new file mode 100644 index 00000000000..699e61202f1 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_ssao.png differ diff --git a/res/dist/media/thumbnails/thumb_terrain.png b/res/dist/media/thumbnails/thumb_terrain.png new file mode 100644 index 00000000000..6634af17be4 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_terrain.png differ diff --git a/res/dist/media/thumbnails/thumb_texarray.png b/res/dist/media/thumbnails/thumb_texarray.png new file mode 100644 index 00000000000..2566f09ad71 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_texarray.png differ diff --git a/res/dist/media/thumbnails/thumb_texfx.png b/res/dist/media/thumbnails/thumb_texfx.png new file mode 100644 index 00000000000..f982ef9e962 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_texfx.png differ diff --git a/res/dist/media/thumbnails/thumb_trans.png b/res/dist/media/thumbnails/thumb_trans.png new file mode 100644 index 00000000000..6957e7faefa Binary files /dev/null and b/res/dist/media/thumbnails/thumb_trans.png differ diff --git a/res/dist/media/thumbnails/thumb_visual_tests.png b/res/dist/media/thumbnails/thumb_visual_tests.png new file mode 100644 index 00000000000..c1edb4e5af7 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_visual_tests.png differ diff --git a/res/dist/media/thumbnails/thumb_voltex.png b/res/dist/media/thumbnails/thumb_voltex.png new file mode 100644 index 00000000000..055f2084217 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_voltex.png differ diff --git a/res/dist/media/thumbnails/thumb_water.png b/res/dist/media/thumbnails/thumb_water.png new file mode 100644 index 00000000000..973b88bbab2 Binary files /dev/null and b/res/dist/media/thumbnails/thumb_water.png differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000000..b2111721e60 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(ogre) \ No newline at end of file diff --git a/src/ogre/BasicTutorial6.cpp b/src/ogre/BasicTutorial6.cpp new file mode 100644 index 00000000000..050076e10a5 --- /dev/null +++ b/src/ogre/BasicTutorial6.cpp @@ -0,0 +1,214 @@ +#include "BasicTutorial6.h" + +#include +#include + +#include +#include +#include +#include + +#include + +//------------------------------------------------------------------------------------- +BasicTutorial6::BasicTutorial6(void) + :mRoot(0), + mPluginsCfg(Ogre::StringUtil::BLANK), + mResourcesCfg(Ogre::StringUtil::BLANK) +{ +} +//------------------------------------------------------------------------------------- +BasicTutorial6::~BasicTutorial6(void) +{ + Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this); + windowClosed(mWindow); + delete mRoot; +} + +bool BasicTutorial6::go(void) +{ + +#ifdef NDEBUG + mPluginsCfg = "plugins.cfg"; + mResourcesCfg = "resources.cfg"; +#else + mResourcesCfg = "resources_d.cfg"; + mPluginsCfg = "plugins_d.cfg"; +#endif + + // construct Ogre::Root + mRoot = new Ogre::Root(mPluginsCfg); + + // Setup resources + Ogre::ConfigFile cf; + cf.load(mResourcesCfg); + + Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); + + Ogre::String secName, typeName, archName; + while(seci.hasMoreElements()) + { + secName = seci.peekNextKey(); + Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); + Ogre::ConfigFile::SettingsMultiMap::iterator i; + for(i = settings->begin(); i != settings->end(); ++i) + { + typeName = i->first; + archName = i->second; + Ogre::ResourceGroupManager::getSingleton().addResourceLocation( + archName, typeName, secName); + } + } + + // configure gfx settings + if(!(mRoot->restoreConfig() || mRoot->showConfigDialog())) + { return false; } + /* optional timesaver for development: + Ogre::RenderSystem *rs = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem"); + mRoot->setRenderSystem(rs); + rs->setConfigOption("Full Screen", "No"); + rs->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour"); */ + + // Render window + mWindow = mRoot->initialise(true, "BasicTutorial 6"); + + // Default mipmap level + Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); + // initialise all resource groups + Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); + + // Create scenemanager + mSceneMgr = mRoot->createSceneManager("DefaultSceneManager"); + + // Create the camera + mCamera = mSceneMgr->createCamera("PlayerCam"); + mCamera->setPosition(Ogre::Vector3(0,0,80)); + mCamera->lookAt(Ogre::Vector3(0,0,-300)); + mCamera->setNearClipDistance(5); + + // Viewport + Ogre::Viewport* vp = mWindow->addViewport(mCamera); + vp->setBackgroundColour(Ogre::ColourValue(0,0,0)); + + mCamera->setAspectRatio( + Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); + + // scene + Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh"); + + Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); + headNode->attachObject(ogreHead); + + // ambient light + mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5,0.5,0.5)); + + // light + Ogre::Light* l = mSceneMgr->createLight("MainLight"); + l->setPosition(20,80,50); + + Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); + OIS::ParamList pl; + size_t windowHnd = 0; + std::ostringstream windowHndStr; + + mWindow->getCustomAttribute("WINDOW", &windowHnd); + windowHndStr << windowHnd; + pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); + + mInputManager = OIS::InputManager::createInputSystem(pl); + + mKeyboard = static_cast(mInputManager->createInputObject( OIS::OISKeyboard, false )); + mMouse = static_cast(mInputManager->createInputObject( OIS::OISMouse, false )); + + // set initial mouse clipping + windowResized(mWindow); + // register window listener + Ogre::WindowEventUtilities::addWindowEventListener(mWindow,this); + + mRoot->addFrameListener(this); + mRoot->startRendering(); + + return true; +} + +/// Adjust mouse clipping area +void BasicTutorial6::windowResized(Ogre::RenderWindow* rw) +{ + unsigned int width, height, depth; + int left, top; + rw->getMetrics(width, height, depth, left, top); + + const OIS::MouseState &ms = mMouse->getMouseState(); + ms.width = width; + ms.height = height; +} + +// Unattach OIS before window shutdown (very important in linux) +void BasicTutorial6::windowClosed(Ogre::RenderWindow* rw) +{ + // only close for window that created OIS + if(rw == mWindow) + { + if(mInputManager) + { + mInputManager->destroyInputObject(mMouse); + mInputManager->destroyInputObject(mKeyboard); + + OIS::InputManager::destroyInputSystem(mInputManager); + mInputManager = 0; + } + } +} + + +bool BasicTutorial6::frameRenderingQueued(const Ogre::FrameEvent& evt) +{ + if(mWindow->isClosed()) + return false; + + // need to capture each device + mKeyboard->capture(); + mMouse->capture(); + + if(mKeyboard->isKeyDown(OIS::KC_ESCAPE)) + return false; + + return true; +} + +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 +#define WIN32_LEAN_AND_MEAN +#include "windows.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) +#else + int main(int argc, char *argv[]) +#endif + { + // Create application object + BasicTutorial6 app; + + try { + app.go(); + } catch( Ogre::Exception& e ) { + // possibly delete ogre.cfg? +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); +#else + std::cerr << "An exception has occured: " << + e.getFullDescription().c_str() << std::endl; +#endif + } + + return 0; + } + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/src/ogre/BasicTutorial6.h b/src/ogre/BasicTutorial6.h new file mode 100644 index 00000000000..39b9c8c33b1 --- /dev/null +++ b/src/ogre/BasicTutorial6.h @@ -0,0 +1,35 @@ +#include + +#include +#include +#include +#include + +#include + +class BasicTutorial6 : public Ogre::WindowEventListener, public Ogre::FrameListener +{ +private: + Ogre::Root* mRoot; + Ogre::String mPluginsCfg; + Ogre::String mResourcesCfg; + Ogre::RenderWindow* mWindow; + + Ogre::SceneManager* mSceneMgr; + Ogre::Camera* mCamera; + + // OIS Input devices + OIS::InputManager* mInputManager; + OIS::Mouse* mMouse; + OIS::Keyboard* mKeyboard; +protected: + /** testing 2 */ + virtual void windowResized(Ogre::RenderWindow* rw); + virtual void windowClosed(Ogre::RenderWindow* rw); + // FrameListener + virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt); +public: + BasicTutorial6(void); + virtual ~BasicTutorial6(void); + bool go(void); +}; \ No newline at end of file diff --git a/src/ogre/CMakeLists.txt b/src/ogre/CMakeLists.txt new file mode 100644 index 00000000000..6ec0084153a --- /dev/null +++ b/src/ogre/CMakeLists.txt @@ -0,0 +1,4 @@ +add_sources( + BasicTutorial6.h + BasicTutorial6.cpp + ) \ No newline at end of file