├── AUTHORS.txt ├── CMakeLists.txt ├── CMakeModules ├── Findfftss.cmake ├── Findfftw3-3.cmake ├── Findfftw3f-3.cmake └── LibFindMacros.cmake ├── LICENSE.txt ├── README.txt ├── demo ├── island │ ├── detail.png │ ├── islands.ive │ ├── moss.png │ └── sand.png └── textures │ ├── sky_clear │ ├── down.png │ ├── east.png │ ├── north.png │ ├── south.png │ ├── up.png │ └── west.png │ ├── sky_dusk │ ├── down.png │ ├── east.png │ ├── north.png │ ├── old │ │ ├── down.png │ │ ├── east.png │ │ ├── north.png │ │ ├── south.png │ │ ├── up.png │ │ └── west.png │ ├── south.png │ ├── up.png │ └── west.png │ └── sky_fair_cloudy │ ├── down.png │ ├── east.png │ ├── north.png │ ├── south.png │ ├── up.png │ └── west.png ├── include ├── OceanExample │ ├── Scene.h │ ├── SceneEventHandler.h │ ├── ScopedTimer.h │ ├── SkyDome.h │ ├── SphereSegment.h │ └── TextHUD.h └── osgOcean │ ├── Cylinder │ ├── DistortionSurface │ ├── Export │ ├── FFTOceanSurface │ ├── FFTOceanSurfaceVBO │ ├── FFTOceanTechnique │ ├── FFTSimulation │ ├── GodRayBlendSurface │ ├── GodRays │ ├── MipmapGeometry │ ├── MipmapGeometryVBO │ ├── OceanScene │ ├── OceanTechnique │ ├── OceanTile │ ├── RandUtils │ ├── ScreenAlignedQuad │ ├── ShaderManager │ ├── SiltEffect │ ├── Version │ ├── WaterTrochoids │ └── shaders │ ├── osgOcean_dof_combiner_frag.inl │ ├── osgOcean_dof_combiner_vert.inl │ ├── osgOcean_downsample_frag.inl │ ├── osgOcean_downsample_glare_frag.inl │ ├── osgOcean_downsample_vert.inl │ ├── osgOcean_gaussian1_frag.inl │ ├── osgOcean_gaussian2_frag.inl │ ├── osgOcean_gaussian_vert.inl │ ├── osgOcean_glare_composite_frag.inl │ ├── osgOcean_glare_composite_vert.inl │ ├── osgOcean_godray_glare_frag.inl │ ├── osgOcean_godray_glare_vert.inl │ ├── osgOcean_godray_screen_blend_frag.inl │ ├── osgOcean_godray_screen_blend_vert.inl │ ├── osgOcean_godrays_frag.inl │ ├── osgOcean_godrays_vert.inl │ ├── osgOcean_heightmap_frag.inl │ ├── osgOcean_heightmap_vert.inl │ ├── osgOcean_ocean_scene_frag.inl │ ├── osgOcean_ocean_scene_lispsm_frag.inl │ ├── osgOcean_ocean_scene_lispsm_vert.inl │ ├── osgOcean_ocean_scene_vert.inl │ ├── osgOcean_ocean_surface_frag.inl │ ├── osgOcean_ocean_surface_vbo_vert.inl │ ├── osgOcean_ocean_surface_vert.inl │ ├── osgOcean_silt_points_frag.inl │ ├── osgOcean_silt_points_vert.inl │ ├── osgOcean_silt_quads_frag.inl │ ├── osgOcean_silt_quads_vert.inl │ ├── osgOcean_streak_frag.inl │ ├── osgOcean_streak_vert.inl │ ├── osgOcean_water_distortion_frag.inl │ └── osgOcean_water_distortion_vert.inl ├── resources ├── shaders │ ├── osgOcean_dof_combiner.frag │ ├── osgOcean_dof_combiner.vert │ ├── osgOcean_downsample.frag │ ├── osgOcean_downsample.vert │ ├── osgOcean_downsample_glare.frag │ ├── osgOcean_gaussian.vert │ ├── osgOcean_gaussian1.frag │ ├── osgOcean_gaussian2.frag │ ├── osgOcean_glare_composite.frag │ ├── osgOcean_glare_composite.vert │ ├── osgOcean_godray_glare.frag │ ├── osgOcean_godray_glare.vert │ ├── osgOcean_godray_screen_blend.frag │ ├── osgOcean_godray_screen_blend.vert │ ├── osgOcean_godrays.frag │ ├── osgOcean_godrays.vert │ ├── osgOcean_heightmap.frag │ ├── osgOcean_heightmap.vert │ ├── osgOcean_ocean_scene.frag │ ├── osgOcean_ocean_scene.vert │ ├── osgOcean_ocean_scene_lispsm.frag │ ├── osgOcean_ocean_scene_lispsm.vert │ ├── osgOcean_ocean_surface.frag │ ├── osgOcean_ocean_surface.vert │ ├── osgOcean_ocean_surface_vbo.vert │ ├── osgOcean_silt_points.frag │ ├── osgOcean_silt_points.vert │ ├── osgOcean_silt_quads.frag │ ├── osgOcean_silt_quads.vert │ ├── osgOcean_streak.frag │ ├── osgOcean_streak.vert │ ├── osgOcean_water_distortion.frag │ ├── osgOcean_water_distortion.vert │ ├── skydome.frag │ ├── skydome.vert │ ├── terrain.frag │ ├── terrain.vert │ ├── terrain_lispsm.frag │ └── terrain_lispsm.vert └── textures │ ├── sea_foam.png │ └── sun_glare.png ├── scripts ├── convert_shaders.py └── copyright_notice.txt └── src ├── CMakeLists.txt ├── oceanExample ├── CMakeLists.txt ├── Scene.cpp ├── SkyDome.cpp ├── SphereSegment.cpp └── application.cpp └── osgOcean ├── CMakeLists.txt ├── Cylinder.cpp ├── DistortionSurface.cpp ├── FFTOceanSurface.cpp ├── FFTOceanSurfaceVBO.cpp ├── FFTOceanTechnique.cpp ├── FFTSimulation.cpp ├── GodRayBlendSurface.cpp ├── GodRays.cpp ├── MipmapGeometry.cpp ├── MipmapGeometryVBO.cpp ├── OceanScene.cpp ├── OceanTechnique.cpp ├── OceanTile.cpp ├── ScreenAlignedQuad.cpp ├── ShaderManager.cpp ├── SiltEffect.cpp ├── Version.cpp └── WaterTrochoids.cpp /AUTHORS.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/AUTHORS.txt -------------------------------------------------------------------------------- /CMakeModules/Findfftss.cmake: -------------------------------------------------------------------------------- 1 | FIND_PATH( 2 | FFTSS_INCLUDE_DIR 3 | NAMES fftw3compat.h 4 | HINTS $ENV{FFTSS_DIR}/include 5 | PATHS /usr/local/include 6 | /usr/include 7 | ) 8 | 9 | FIND_LIBRARY( 10 | FFTSS_LIBRARY 11 | NAMES fftss libfftss 12 | HINTS $ENV{FFTSS_DIR}/lib 13 | PATHS /usr/local/lib 14 | /usr/lib 15 | ) 16 | 17 | SET(FFTSS_FOUND "NO") 18 | 19 | IF( FFTSS_INCLUDE_DIR AND FFTSS_LIBRARY ) 20 | SET(FFTSS_FOUND "YES") 21 | ENDIF() 22 | -------------------------------------------------------------------------------- /CMakeModules/Findfftw3-3.cmake: -------------------------------------------------------------------------------- 1 | # Find double-precision (double) version of FFTW3 2 | 3 | FIND_PATH( 4 | FFTW3-3_INCLUDE_DIR 5 | NAMES fftw3.h 6 | HINTS $ENV{FFTW3_DIR}/include 7 | PATHS /usr/local/include 8 | /usr/include 9 | ) 10 | 11 | FIND_LIBRARY( 12 | FFTW3-3_LIBRARY 13 | NAMES fftw3-3 libfftw3-3 14 | HINTS $ENV{FFTW3_DIR}/lib 15 | PATHS /usr/local/lib 16 | /usr/lib 17 | ) 18 | 19 | SET(FFTW3_FOUND "NO") 20 | 21 | IF( FFTW3-3_INCLUDE_DIR AND FFTW3-3_LIBRARY ) 22 | SET(FFTW3_FOUND "YES") 23 | ENDIF() 24 | -------------------------------------------------------------------------------- /CMakeModules/Findfftw3f-3.cmake: -------------------------------------------------------------------------------- 1 | # Find single-precision (float) version of FFTW3 2 | 3 | FIND_PATH( 4 | FFTW3F-3_INCLUDE_DIR 5 | NAMES fftw3.h 6 | HINTS $ENV{FFTW3_DIR}/include 7 | PATHS /usr/local/include 8 | /usr/include 9 | ) 10 | 11 | FIND_LIBRARY( 12 | FFTW3F-3_LIBRARY 13 | NAMES fftw3f libfftw3f-3 14 | HINTS $ENV{FFTW3_DIR}/lib 15 | PATHS /usr/local/lib 16 | /usr/lib 17 | ) 18 | 19 | SET(FFTW_FOUND "NO") 20 | 21 | IF( FFTW3F-3_INCLUDE_DIR AND FFTW3F-3_LIBRARY ) 22 | SET(FFTW_FOUND "YES") 23 | ENDIF() 24 | -------------------------------------------------------------------------------- /CMakeModules/LibFindMacros.cmake: -------------------------------------------------------------------------------- 1 | # Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments 2 | # used for the current package. For this to work, the first parameter must be the 3 | # prefix of the current package, then the prefix of the new package etc, which are 4 | # passed to find_package. 5 | macro (libfind_package PREFIX) 6 | set (LIBFIND_PACKAGE_ARGS ${ARGN}) 7 | if (${PREFIX}_FIND_QUIETLY) 8 | set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) 9 | endif (${PREFIX}_FIND_QUIETLY) 10 | if (${PREFIX}_FIND_REQUIRED) 11 | set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) 12 | endif (${PREFIX}_FIND_REQUIRED) 13 | find_package(${LIBFIND_PACKAGE_ARGS}) 14 | endmacro (libfind_package) 15 | 16 | # Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6) 17 | # where they added pkg_check_modules. Consequently I need to support both in my scripts 18 | # to avoid those deprecated warnings. Here's a helper that does just that. 19 | # Works identically to pkg_check_modules, except that no checks are needed prior to use. 20 | macro (libfind_pkg_check_modules PREFIX PKGNAME) 21 | if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 22 | include(UsePkgConfig) 23 | pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) 24 | else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 25 | find_package(PkgConfig) 26 | if (PKG_CONFIG_FOUND) 27 | pkg_check_modules(${PREFIX} ${PKGNAME}) 28 | endif (PKG_CONFIG_FOUND) 29 | endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 30 | endmacro (libfind_pkg_check_modules) 31 | 32 | # Do the final processing once the paths have been detected. 33 | # If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain 34 | # all the variables, each of which contain one include directory. 35 | # Ditto for ${PREFIX}_PROCESS_LIBS and library files. 36 | # Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. 37 | # Also handles errors in case library detection was required, etc. 38 | macro (libfind_process PREFIX) 39 | # Skip processing if already processed during this run 40 | if (NOT ${PREFIX}_FOUND) 41 | # Start with the assumption that the library was found 42 | set (${PREFIX}_FOUND TRUE) 43 | 44 | # Process all includes and set _FOUND to false if any are missing 45 | foreach (i ${${PREFIX}_PROCESS_INCLUDES}) 46 | if (${i}) 47 | set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) 48 | mark_as_advanced(${i}) 49 | else (${i}) 50 | set (${PREFIX}_FOUND FALSE) 51 | endif (${i}) 52 | endforeach (i) 53 | 54 | # Process all libraries and set _FOUND to false if any are missing 55 | foreach (i ${${PREFIX}_PROCESS_LIBS}) 56 | if (${i}) 57 | set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) 58 | mark_as_advanced(${i}) 59 | else (${i}) 60 | set (${PREFIX}_FOUND FALSE) 61 | endif (${i}) 62 | endforeach (i) 63 | 64 | # Print message and/or exit on fatal error 65 | if (${PREFIX}_FOUND) 66 | if (NOT ${PREFIX}_FIND_QUIETLY) 67 | message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") 68 | endif (NOT ${PREFIX}_FIND_QUIETLY) 69 | else (${PREFIX}_FOUND) 70 | if (${PREFIX}_FIND_REQUIRED) 71 | foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) 72 | message("${i}=${${i}}") 73 | endforeach (i) 74 | message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") 75 | endif (${PREFIX}_FIND_REQUIRED) 76 | endif (${PREFIX}_FOUND) 77 | endif (NOT ${PREFIX}_FOUND) 78 | endmacro (libfind_process) 79 | 80 | macro(libfind_library PREFIX basename) 81 | set(TMP "") 82 | if(MSVC80) 83 | set(TMP -vc80) 84 | endif(MSVC80) 85 | if(MSVC90) 86 | set(TMP -vc90) 87 | endif(MSVC90) 88 | set(${PREFIX}_LIBNAMES ${basename}${TMP}) 89 | if(${ARGC} GREATER 2) 90 | set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) 91 | string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) 92 | set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) 93 | endif(${ARGC} GREATER 2) 94 | find_library(${PREFIX}_LIBRARY 95 | NAMES ${${PREFIX}_LIBNAMES} 96 | PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} 97 | ) 98 | endmacro(libfind_library) 99 | 100 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | osgOcean v1.0 2 | ------------- 3 | 4 | DEPENDANCIES 5 | ------------ 6 | 7 | Resources 8 | --------- 9 | 10 | Both the library and the example require a set of resource 11 | files (models/textures) which can be downloaded from here: 12 | http://osgocean.googlecode.com/files/osgOcean-Resources-1.0.rar 13 | 14 | Once you downloaded them, extract the 'Island' and 'Textures' 15 | folders into the resources directory found in the root of the 16 | source code tree. The install project will copy the relevant 17 | data files to the bin path like so: 18 | 19 | *install_path*/bin/resources/ 20 | 21 | osgOcean uses the osgDB registry to find the resource files. 22 | By default it adds the following paths to the registry: 23 | 24 | Shader path: 25 | resources/shaders/ 26 | 27 | Texture path: 28 | resources/textures/ 29 | 30 | If you wish to move these resources you must update the data file path 31 | list within the registry yourself. This can be down from outside the 32 | library with the following code: 33 | 34 | osgDB::FilePathList& pathList = osgDB::Registry::instance()->getDataFilePathList(); 35 | pathList.push_back( new_path ); 36 | 37 | Libraries 38 | --------- 39 | 40 | osgOcean also requires a Fast Fourier Transform library. It can work 41 | with either FFTW or FFTSS. 42 | 43 | **IMPORTANT LICENSE ISSUE** 44 | FFTW is released under a General Public License, by selecting this 45 | option in CMAKE the resulting build of osgOcean will also be covered under 46 | the GPL license. 47 | 48 | GPL License details: http://www.gnu.org/copyleft/gpl.html 49 | 50 | FFTSS is covered under a Lesser General Public License which allows 51 | the osgOcean library to remain LGPL. 52 | 53 | LGPL License details: http://www.gnu.org/licenses/lgpl.html or see LICENSE.txt 54 | 55 | FFTW and FFTSS can be downloaded from: 56 | 57 | FFTW: http://www.fftw.org/ 58 | FFTSS: http://www.ssisc.org/fftss/ 59 | -------------------------------------------------------------------------------- /demo/island/detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/island/detail.png -------------------------------------------------------------------------------- /demo/island/islands.ive: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/island/islands.ive -------------------------------------------------------------------------------- /demo/island/moss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/island/moss.png -------------------------------------------------------------------------------- /demo/island/sand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/island/sand.png -------------------------------------------------------------------------------- /demo/textures/sky_clear/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_clear/down.png -------------------------------------------------------------------------------- /demo/textures/sky_clear/east.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_clear/east.png -------------------------------------------------------------------------------- /demo/textures/sky_clear/north.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_clear/north.png -------------------------------------------------------------------------------- /demo/textures/sky_clear/south.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_clear/south.png -------------------------------------------------------------------------------- /demo/textures/sky_clear/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_clear/up.png -------------------------------------------------------------------------------- /demo/textures/sky_clear/west.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_clear/west.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/down.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/east.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/east.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/north.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/north.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/old/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/old/down.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/old/east.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/old/east.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/old/north.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/old/north.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/old/south.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/old/south.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/old/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/old/up.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/old/west.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/old/west.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/south.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/south.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/up.png -------------------------------------------------------------------------------- /demo/textures/sky_dusk/west.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_dusk/west.png -------------------------------------------------------------------------------- /demo/textures/sky_fair_cloudy/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_fair_cloudy/down.png -------------------------------------------------------------------------------- /demo/textures/sky_fair_cloudy/east.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_fair_cloudy/east.png -------------------------------------------------------------------------------- /demo/textures/sky_fair_cloudy/north.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_fair_cloudy/north.png -------------------------------------------------------------------------------- /demo/textures/sky_fair_cloudy/south.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_fair_cloudy/south.png -------------------------------------------------------------------------------- /demo/textures/sky_fair_cloudy/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_fair_cloudy/up.png -------------------------------------------------------------------------------- /demo/textures/sky_fair_cloudy/west.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/demo/textures/sky_fair_cloudy/west.png -------------------------------------------------------------------------------- /include/OceanExample/Scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "SkyDome.h" 12 | 13 | 14 | enum DrawMask 15 | { 16 | CAST_SHADOW = (0x1<<30), 17 | RECEIVE_SHADOW = (0x1<<29), 18 | }; 19 | 20 | 21 | class Scene : public osg::Referenced 22 | { 23 | public: 24 | enum SCENE_TYPE{ CLEAR, DUSK, CLOUDY }; 25 | 26 | private: 27 | SCENE_TYPE _sceneType; 28 | bool _useVBO; 29 | 30 | osg::ref_ptr _modeText; 31 | osg::ref_ptr _scene; 32 | 33 | osg::ref_ptr _oceanScene; 34 | osg::ref_ptr _FFToceanSurface; 35 | osg::ref_ptr _cubemap; 36 | osg::ref_ptr _skyDome; 37 | 38 | std::vector _cubemapDirs; 39 | std::vector _lightColors; 40 | std::vector _fogColors; 41 | std::vector _underwaterAttenuations; 42 | std::vector _underwaterDiffuse; 43 | 44 | osg::ref_ptr _light; 45 | 46 | std::vector _sunPositions; 47 | std::vector _sunDiffuse; 48 | std::vector _waterFogColors; 49 | 50 | osg::ref_ptr _islandSwitch; 51 | 52 | public: 53 | Scene( 54 | const osg::Vec2f& windDirection = osg::Vec2f(1.0f,1.0f), 55 | float windSpeed = 12.f, 56 | float depth = 10000.f, 57 | float reflectionDamping = 0.35f, 58 | float scale = 1e-8, 59 | bool isChoppy = true, 60 | float choppyFactor = -2.5f, 61 | float crestFoamHeight = 2.2f, 62 | bool useVBO=false, 63 | const std::string& terrain_shader_basename = "terrain" ); 64 | 65 | void build( 66 | const osg::Vec2f& windDirection, 67 | float windSpeed, 68 | float depth, 69 | float reflectionDamping, 70 | float waveScale, 71 | bool isChoppy, 72 | float choppyFactor, 73 | float crestFoamHeight, 74 | bool useVBO, 75 | const std::string& terrain_shader_basename ); 76 | 77 | void changeScene( SCENE_TYPE type ); 78 | 79 | // Load the islands model 80 | // Here we attach a custom shader to the model. 81 | // This shader overrides the default shader applied by OceanScene but uses uniforms applied by OceanScene. 82 | // The custom shader is needed to add multi-texturing and bump mapping to the terrain. 83 | osg::Node* loadIslands(const std::string& terrain_shader_basename); 84 | 85 | osg::ref_ptr loadCubeMapTextures( const std::string& dir ); 86 | 87 | osg::Geode* sunDebug( const osg::Vec3f& position ); 88 | 89 | inline osg::Vec4f intColor(unsigned r, unsigned g, unsigned b, unsigned a = 255 ) 90 | { 91 | float div = 1.f/255.f; 92 | return osg::Vec4f( div*(float)r, div*(float)g, div*float(b), div*(float)a ); 93 | } 94 | 95 | inline osgOcean::OceanScene::EventHandler* getOceanSceneEventHandler() 96 | { 97 | return _oceanScene->getEventHandler(); 98 | } 99 | 100 | inline osgOcean::OceanTechnique* getOceanSurface( void ) 101 | { 102 | return _FFToceanSurface.get(); 103 | } 104 | 105 | inline osg::Group* getScene(void){ 106 | return _scene.get(); 107 | } 108 | 109 | inline osgOcean::OceanScene* getOceanScene() 110 | { 111 | return _oceanScene.get(); 112 | } 113 | 114 | osg::Light* getLight() { return _light.get(); } 115 | }; -------------------------------------------------------------------------------- /include/OceanExample/SceneEventHandler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "TextHUD.h" 8 | #include "Scene.h" 9 | 10 | // ---------------------------------------------------- 11 | // Event Handler 12 | // ---------------------------------------------------- 13 | 14 | class SceneEventHandler : public osgGA::GUIEventHandler 15 | { 16 | private: 17 | osg::ref_ptr _scene; 18 | osg::ref_ptr _textHUD; 19 | osgViewer::View* _view; 20 | osg::Vec3 _initialCameraPosition; 21 | 22 | enum CameraMode 23 | { 24 | FIXED, 25 | FLIGHT, 26 | TRACKBALL 27 | }; 28 | 29 | CameraMode _currentCameraMode; 30 | 31 | public: 32 | SceneEventHandler( Scene* scene, TextHUD* textHUD, osgViewer::View* view, const osg::Vec3& initialCameraPosition ) 33 | :_scene (scene) 34 | ,_textHUD (textHUD) 35 | ,_view (view) 36 | ,_currentCameraMode (FIXED) 37 | ,_initialCameraPosition(initialCameraPosition) 38 | { 39 | _textHUD->setSceneText("Clear"); 40 | _textHUD->setCameraText("FIXED"); 41 | 42 | osg::Vec3f eye(_initialCameraPosition); 43 | osg::Vec3f centre = eye+osg::Vec3f(0.f,1.f,0.f); 44 | osg::Vec3f up(0.f, 0.f, 1.f); 45 | 46 | _view->getCamera()->setViewMatrixAsLookAt( eye, centre, up ); 47 | } 48 | 49 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) 50 | { 51 | switch(ea.getEventType()) 52 | { 53 | case(osgGA::GUIEventAdapter::KEYUP): 54 | { 55 | if(ea.getKey() == '1') 56 | { 57 | _scene->changeScene( Scene::CLEAR ); 58 | _textHUD->setSceneText( "Clear Blue Sky" ); 59 | return false; 60 | } 61 | else if(ea.getKey() == '2') 62 | { 63 | _scene->changeScene( Scene::DUSK ); 64 | _textHUD->setSceneText( "Dusk" ); 65 | return false; 66 | } 67 | else if(ea.getKey() == '3' ) 68 | { 69 | _scene->changeScene( Scene::CLOUDY ); 70 | _textHUD->setSceneText( "Pacific Cloudy" ); 71 | return false; 72 | } 73 | else if(ea.getKey() == 'C' || ea.getKey() == 'c' ) 74 | { 75 | osg::Vec3 eye(_initialCameraPosition); 76 | if (_currentCameraMode == FIXED) 77 | { 78 | _currentCameraMode = FLIGHT; 79 | osgGA::FlightManipulator* flight = new osgGA::FlightManipulator; 80 | flight->setHomePosition( eye, eye + osg::Vec3(0,1,0), osg::Vec3f(0,0,1) ); 81 | _view->setCameraManipulator( flight ); 82 | _textHUD->setCameraText("FLIGHT"); 83 | } 84 | else if (_currentCameraMode == FLIGHT) 85 | { 86 | _currentCameraMode = TRACKBALL; 87 | osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator; 88 | tb->setHomePosition( eye, eye + osg::Vec3(0,20,0), osg::Vec3f(0,0,1) ); 89 | _view->setCameraManipulator( tb ); 90 | _textHUD->setCameraText("TRACKBALL"); 91 | } 92 | else if (_currentCameraMode == TRACKBALL) 93 | { 94 | _currentCameraMode = FIXED; 95 | _view->getCamera()->setViewMatrixAsLookAt( eye, eye + osg::Vec3(0,1,0), osg::Vec3f(0,0,1) ); 96 | _view->setCameraManipulator(NULL); 97 | _textHUD->setCameraText("FIXED"); 98 | } 99 | } 100 | } 101 | default: 102 | return false; 103 | } 104 | } 105 | 106 | void getUsage(osg::ApplicationUsage& usage) const 107 | { 108 | usage.addKeyboardMouseBinding("c","Camera type (cycle through Fixed, Flight, Trackball)"); 109 | usage.addKeyboardMouseBinding("1","Select scene \"Clear Blue Sky\""); 110 | usage.addKeyboardMouseBinding("2","Select scene \"Dusk\""); 111 | usage.addKeyboardMouseBinding("3","Select scene \"Pacific Cloudy\""); 112 | } 113 | }; -------------------------------------------------------------------------------- /include/OceanExample/ScopedTimer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | // ---------------------------------------------------- 7 | // Scoped timer 8 | // ---------------------------------------------------- 9 | 10 | class ScopedTimer 11 | { 12 | public: 13 | ScopedTimer( const std::string& description, 14 | std::ostream& output_stream = std::cout, 15 | bool endline_after_time = true) 16 | : _output_stream(output_stream) 17 | , _start() 18 | , _endline_after_time(endline_after_time) 19 | { 20 | _output_stream << description << std::flush; 21 | _start = osg::Timer::instance()->tick(); 22 | } 23 | 24 | ~ScopedTimer() 25 | { 26 | osg::Timer_t end = osg::Timer::instance()->tick(); 27 | 28 | _output_stream << osg::Timer::instance()->delta_s(_start, end) << "s"; 29 | 30 | if (_endline_after_time) 31 | { 32 | _output_stream << std::endl; 33 | } 34 | else 35 | { 36 | _output_stream << std::flush; 37 | } 38 | } 39 | 40 | private: 41 | std::ostream& _output_stream; 42 | osg::Timer_t _start; 43 | bool _endline_after_time; 44 | }; -------------------------------------------------------------------------------- /include/OceanExample/SkyDome.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include "SphereSegment.h" 20 | #include 21 | #include 22 | #include 23 | 24 | class SkyDome : public SphereSegment 25 | { 26 | public: 27 | SkyDome( void ); 28 | SkyDome( const SkyDome& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ); 29 | SkyDome( float radius, unsigned int longSteps, unsigned int latSteps, osg::TextureCubeMap* cubemap ); 30 | 31 | protected: 32 | ~SkyDome(void); 33 | 34 | public: 35 | void setupStateSet( osg::TextureCubeMap* cubemap ); 36 | void create( float radius, unsigned int latSteps, unsigned int longSteps, osg::TextureCubeMap* cubemap ); 37 | 38 | inline void setCubeMap( osg::TextureCubeMap* cubemap ){ 39 | getOrCreateStateSet()->setTextureAttributeAndModes( 0, cubemap, osg::StateAttribute::ON ); 40 | } 41 | 42 | private: 43 | osg::ref_ptr createShader(void); 44 | 45 | }; 46 | -------------------------------------------------------------------------------- /include/OceanExample/SphereSegment.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | 22 | class SphereSegment : public osg::Geode 23 | { 24 | public: 25 | SphereSegment( void ); 26 | 27 | SphereSegment( float radius, 28 | unsigned int longitudeSteps, 29 | unsigned int lattitudeSteps, 30 | float longStart, 31 | float longEnd, 32 | float latStart, 33 | float latEnd ); 34 | 35 | SphereSegment(const SphereSegment& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 36 | 37 | protected: 38 | ~SphereSegment(void); 39 | 40 | public: 41 | // 0 >= longStart/longEnd <= 180 42 | // 0 >= latStart/latEnd <= 360 43 | void compute( float radius, 44 | unsigned int longitudeSteps, 45 | unsigned int lattitudeSteps, 46 | float longStart, 47 | float longEnd, 48 | float latStart, 49 | float latEnd ); 50 | private: 51 | osg::Vec2 sphereMap( osg::Vec3& vertex, float radius); 52 | 53 | inline unsigned int idx(unsigned int r, unsigned int c, unsigned int row_len) 54 | { 55 | return c + r * row_len; 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /include/OceanExample/TextHUD.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | // ---------------------------------------------------- 10 | // Text HUD Class 11 | // ---------------------------------------------------- 12 | 13 | class TextHUD : public osg::Referenced 14 | { 15 | private: 16 | osg::ref_ptr< osg::Camera > _camera; 17 | osg::ref_ptr< osgText::Text > _modeText; 18 | osg::ref_ptr< osgText::Text > _cameraModeText; 19 | 20 | public: 21 | TextHUD( void ){ 22 | _camera = createCamera(); 23 | _camera->addChild( createText() ); 24 | } 25 | 26 | osg::Camera* createCamera( void ) 27 | { 28 | osg::Camera* camera=new osg::Camera; 29 | 30 | camera->setViewport(0,0,1024,768); 31 | camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF ); 32 | camera->setProjectionMatrixAsOrtho2D(0,1024,0,768); 33 | camera->setRenderOrder(osg::Camera::POST_RENDER); 34 | camera->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); 35 | camera->setClearMask(GL_DEPTH_BUFFER_BIT); 36 | 37 | return camera; 38 | } 39 | 40 | osg::Node* createText( void ) 41 | { 42 | osg::Geode* textGeode = new osg::Geode; 43 | 44 | osgText::Text* title = new osgText::Text; 45 | title->setFont("fonts/arial.ttf"); 46 | title->setCharacterSize(14); 47 | title->setLineSpacing(0.4f); 48 | 49 | std::string versionText = 50 | std::string("osgOcean ") + 51 | std::string(osgOceanGetVersion()) + 52 | std::string("\nPress 'h' for options"); 53 | 54 | title->setText(versionText); 55 | textGeode->addDrawable( title ); 56 | 57 | _modeText = new osgText::Text; 58 | _modeText->setFont("fonts/arial.ttf"); 59 | _modeText->setCharacterSize(14); 60 | _modeText->setPosition( osg::Vec3f(0.f, -40.f, 0.f ) ); 61 | _modeText->setDataVariance(osg::Object::DYNAMIC); 62 | textGeode->addDrawable( _modeText.get() ); 63 | 64 | _cameraModeText = new osgText::Text; 65 | _cameraModeText->setFont("fonts/arial.ttf"); 66 | _cameraModeText->setCharacterSize(14); 67 | _cameraModeText->setPosition( osg::Vec3f(0.f, -60.f, 0.f ) ); 68 | _cameraModeText->setDataVariance(osg::Object::DYNAMIC); 69 | textGeode->addDrawable( _cameraModeText.get() ); 70 | 71 | osg::PositionAttitudeTransform* titlePAT = new osg::PositionAttitudeTransform; 72 | titlePAT->setPosition( osg::Vec3f( 10, 70, 0.f ) ); 73 | titlePAT->addChild(textGeode); 74 | 75 | return titlePAT; 76 | } 77 | 78 | void setSceneText( const std::string& preset ) 79 | { 80 | _modeText->setText( "Preset: " + preset ); 81 | } 82 | 83 | void setCameraText(const std::string& mode ) 84 | { 85 | _cameraModeText->setText( "Camera: " + mode ); 86 | } 87 | 88 | osg::Camera* getHudCamera(void) 89 | { 90 | return _camera.get(); 91 | } 92 | }; -------------------------------------------------------------------------------- /include/osgOcean/Cylinder: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | 22 | namespace osgOcean 23 | { 24 | 25 | class Cylinder : public osg::Geometry 26 | { 27 | protected: 28 | osg::ref_ptr _colorArray; 29 | float _radius; 30 | float _height; 31 | unsigned _steps; 32 | bool _hasTop; 33 | bool _hasBottom; 34 | 35 | public: 36 | Cylinder( void ); 37 | 38 | Cylinder( float radius, float height, unsigned int steps, bool hasTop, bool hasBottom ); 39 | 40 | Cylinder( const Cylinder& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ); 41 | 42 | protected: 43 | virtual ~Cylinder(void); 44 | 45 | public: 46 | virtual void build( float radius, float height, unsigned int steps, bool top, bool bottom ); 47 | virtual void build( void ); 48 | 49 | void setColor(const osg::Vec4f& color); 50 | 51 | inline const float getRadius( void ) const{ 52 | return _radius; 53 | } 54 | 55 | inline const float getHeight( void ) const{ 56 | return _height; 57 | } 58 | 59 | inline const unsigned getSteps( void ) const{ 60 | return _steps; 61 | } 62 | 63 | inline const bool hasTop( void ) const{ 64 | return _hasTop; 65 | } 66 | 67 | inline const bool hasBottom( void ) const{ 68 | return _hasBottom; 69 | } 70 | }; 71 | 72 | } 73 | -------------------------------------------------------------------------------- /include/osgOcean/DistortionSurface: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | namespace osgOcean 25 | { 26 | class OSGOCEAN_EXPORT DistortionSurface : public osg::Geode 27 | { 28 | public: 29 | DistortionSurface( void ); 30 | 31 | DistortionSurface( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture ); 32 | 33 | DistortionSurface( const DistortionSurface ©, 34 | const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY ); 35 | 36 | virtual const char* libraryName() const { return "osgOcean"; } 37 | virtual const char* className() const { return "DistortionSurface"; } 38 | virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj) != 0; } 39 | 40 | void build( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture ); 41 | 42 | void update(void); 43 | 44 | private: 45 | float _angle; 46 | 47 | protected: 48 | ~DistortionSurface( void ){}; 49 | 50 | /** 51 | * Add the default resource paths to osgDB::Registry. 52 | * Checks if already present. 53 | * paths: resources/textures and resources/shaders. 54 | */ 55 | void addResourcePaths(void); 56 | 57 | private: 58 | void update(const double& dt); 59 | osg::Program* createShader(void); 60 | 61 | private: 62 | // --------------------------------------------- 63 | // Callback declarations 64 | // --------------------------------------------- 65 | 66 | class DistortionDataType : public osg::Referenced 67 | { 68 | private: 69 | DistortionSurface& _surface; 70 | double _oldTime; 71 | double _newTime; 72 | 73 | public: 74 | DistortionDataType( DistortionSurface& surface ); 75 | 76 | void update( const double& time ); 77 | }; 78 | 79 | class DistortionCallback: public osg::NodeCallback 80 | { 81 | public: 82 | virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); 83 | }; 84 | }; 85 | } 86 | -------------------------------------------------------------------------------- /include/osgOcean/Export: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #ifndef OSGOCEAN_EXPORT_ 19 | #define OSGOCEAN_EXPORT_ 1 20 | 21 | #if defined(_MSC_VER) 22 | #pragma warning( disable : 4121 ) 23 | #pragma warning( disable : 4244 ) 24 | #pragma warning( disable : 4251 ) 25 | #pragma warning( disable : 4267 ) 26 | #pragma warning( disable : 4275 ) 27 | #pragma warning( disable : 4290 ) 28 | #pragma warning( disable : 4786 ) 29 | #pragma warning( disable : 4305 ) 30 | #pragma warning( disable : 4996 ) 31 | #endif 32 | 33 | #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) 34 | # if defined( OSG_LIBRARY_STATIC ) 35 | # define OSGOCEAN_EXPORT 36 | # elif defined( OSGOCEAN_LIBRARY ) 37 | # define OSGOCEAN_EXPORT __declspec(dllexport) 38 | # else 39 | # define OSGOCEAN_EXPORT __declspec(dllimport) 40 | # endif 41 | #else 42 | # define OSGOCEAN_EXPORT 43 | #endif 44 | 45 | /** 46 | 47 | \namespace osgOcean 48 | 49 | Some comment about what osgOcean is 50 | */ 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/osgOcean/FFTSimulation: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | 23 | namespace osgOcean 24 | { 25 | /** Implementation of Jerry Tessendorf's FFT Ocean Simulation 26 | * For more information see his paper "Simulating Ocean Water" 27 | * http://graphics.ucsd.edu/courses/rendering/2005/jdewall/tessendorf.pdf 28 | */ 29 | class OSGOCEAN_EXPORT FFTSimulation 30 | { 31 | private: 32 | // Implementation hidden so that clients do not need to depend on the 33 | // FFT library's headers. All calls to FFTSimulation are delegated to 34 | // the private Implementation class. 35 | class Implementation; 36 | Implementation* _implementation; 37 | 38 | public: 39 | 40 | /** Constructor. 41 | * Provides default parameters for a calm ocean surface. 42 | * Computes base amplitudes and initialises FFT plans and arrays. 43 | * @param fourierSize Size of FFT grid 2^n ie 128,64,32 etc. 44 | * @param windDir Direction of wind. 45 | * @param windSpeed Speed of wind (m/s). 46 | * @param waveScale Wave height modifier. 47 | * @param loopTime Time for animation to repeat (secs). 48 | */ 49 | FFTSimulation( 50 | int fourierSize = 64, 51 | const osg::Vec2f& windDir = osg::Vec2f(1.0f, 1.0f), 52 | float windSpeed = 12.f, 53 | float depth = 1000.f, 54 | float reflectionDamping = 0.35f, 55 | float waveScale = 1e-9, 56 | float tileRes = 256.f, 57 | float loopTime = 10.f 58 | ); 59 | 60 | /** Destructor. 61 | * Cleans up FFT plans and arrays. 62 | */ 63 | ~FFTSimulation(void); 64 | 65 | /** Set the current time and computes the current fourier amplitudes */ 66 | void setTime(float time); 67 | 68 | /** Compute the current height field. 69 | * Executes an FFT transform to convert the current fourier amplitudes to real height values. 70 | * @param heights must be created before passing in. Function will resize and overwrite the contents with current data. 71 | */ 72 | void computeHeights( osg::FloatArray* heights ) const; 73 | 74 | /** Compute the (x,y) displacements for choppy wave effect 75 | * Executes two FFT transforms to convert the current fourier amplitudes to real x,y displacements 76 | * @param scaleFactor defines the magnitude of the displacements. Typically a negative value ( -3.0 > val < -1.0 ). 77 | * @param waveDisplacements must be created before passing in. Function will resize and overwrite the contents with the computed displacements. 78 | */ 79 | void computeDisplacements( const float& scaleFactor, osg::Vec2Array* waveDisplacements ) const; 80 | }; 81 | } 82 | -------------------------------------------------------------------------------- /include/osgOcean/MipmapGeometry: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | 22 | namespace osgOcean 23 | { 24 | /** 25 | * Stores mipmap geometry and associated mipmap level data. 26 | */ 27 | class OSGOCEAN_EXPORT MipmapGeometry : public osg::Geometry 28 | { 29 | public: 30 | enum BORDER_TYPE{ BORDER_X, BORDER_Y, BORDER_XY, BORDER_NONE }; 31 | 32 | private: 33 | unsigned int _level; /**< Mipmap level 0 is highest level. */ 34 | unsigned int _numLevels; /**< Number of mipmap levels in use. */ 35 | unsigned int _resolution; /**< Tile size (n^2). */ 36 | unsigned int _rowLen; /**< Length of rows. */ 37 | unsigned int _colLen; /**< Length of cols. */ 38 | unsigned int _startIdx; /**< Start position in vertex array. */ 39 | 40 | BORDER_TYPE _border; /**< is the patch a border piece. */ 41 | 42 | public: 43 | /** 44 | * Default constructor. 45 | * Initialises all values to 0. 46 | */ 47 | MipmapGeometry( void ); 48 | 49 | /** 50 | * Constructor. 51 | * @param level Tile level. 52 | * @param numLevels Number of levels in the mipmap sequence. 53 | * @param startIdx The position of the first vertex in the main vertex array. 54 | * @param border Tiles border type. 55 | */ 56 | MipmapGeometry( unsigned int level, 57 | unsigned int numLevels, 58 | unsigned int startIdx, 59 | BORDER_TYPE border ); 60 | 61 | MipmapGeometry( const MipmapGeometry& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ); 62 | 63 | virtual const char* libraryName() const { return "osgOcean"; } 64 | virtual const char* className() const { return "MipmapGeometry"; } 65 | virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj) != 0; } 66 | 67 | protected: 68 | ~MipmapGeometry( void ); 69 | 70 | public: 71 | inline unsigned int getLevel( void ) const { 72 | return _level; 73 | } 74 | 75 | inline unsigned int getResolution( void ) const { 76 | return _resolution; 77 | } 78 | 79 | inline unsigned int getRowLen( void ) const { 80 | return _rowLen; 81 | } 82 | 83 | inline unsigned int getColLen( void ) const { 84 | return _colLen; 85 | } 86 | 87 | inline BORDER_TYPE getBorder( void ) const { 88 | return _border; 89 | } 90 | 91 | /** 92 | * Sets the level of the mipmap tile. 93 | * Automatically updates the resolution, row and column lengths of the tile. 94 | */ 95 | inline void setLevel( unsigned int level ) 96 | { 97 | _level = level; 98 | _resolution = level != (_numLevels-1) ? 2 << (_numLevels-(level+2) ) : 1; 99 | _rowLen = _border==BORDER_X || _border==BORDER_XY ? _resolution+1 : _resolution; 100 | _colLen = _border==BORDER_Y || _border==BORDER_XY ? _resolution+1 : _resolution; 101 | } 102 | 103 | inline const PrimitiveSetList& getPrimitives( void ) const { 104 | return _primitives; 105 | } 106 | 107 | inline unsigned int getIdx( void ) const { 108 | return _startIdx; 109 | } 110 | 111 | inline void setIdx( unsigned int idx ) { 112 | _startIdx = idx; 113 | } 114 | 115 | inline unsigned int getIndex( unsigned int c, unsigned r ) 116 | { 117 | return _startIdx + (c + r * _rowLen); 118 | } 119 | }; 120 | } 121 | -------------------------------------------------------------------------------- /include/osgOcean/OceanTechnique: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace osgOcean 25 | { 26 | class OSGOCEAN_EXPORT OceanTechnique : public osg::Geode 27 | { 28 | public: 29 | OceanTechnique( void ); 30 | OceanTechnique( const OceanTechnique& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ); 31 | 32 | virtual const char* libraryName() const { return "osgOcean"; } 33 | virtual const char* className() const { return "OceanTechnique"; } 34 | virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj) != 0; } 35 | 36 | virtual void build( void ); 37 | 38 | virtual void stopAnimation( void ){ 39 | _isAnimating = false; 40 | } 41 | 42 | virtual void startAnimation( void ){ 43 | _isAnimating = true; 44 | } 45 | 46 | bool isAnimating( void ) const{ 47 | return _isAnimating; 48 | } 49 | 50 | /** 51 | * Returns the average height over the whole surface (in local space) 52 | */ 53 | virtual float getSurfaceHeight(void) const; 54 | 55 | /** 56 | * Returns the height at the given point (in local space). If the 57 | * address of a Vec3f is passed in the normal argument, the normal at 58 | * that position will be calculated and stored in it. 59 | */ 60 | virtual float getSurfaceHeightAt(float x, float y, osg::Vec3f* normal = NULL) = 0; 61 | 62 | /** 63 | * Returns the maximum height over the whole surface (in local space) 64 | */ 65 | virtual float getMaximumHeight(void) const; 66 | 67 | inline bool isDirty(void) const{ 68 | return _isDirty; 69 | } 70 | 71 | inline void dirty(void){ 72 | _isDirty=true; 73 | } 74 | 75 | /** 76 | * Check if the ocean surface is visible or not. Basic test is very 77 | * simple, subclasses can do a better test. 78 | */ 79 | bool isVisible( osgUtil::CullVisitor& cv, bool eyeAboveWater ); 80 | 81 | /** Base class for the OceanTechnique event handler. Subclasses of 82 | * OceanTechnique can subclass this to provide support for 83 | * manipulating their particular properties, calling the base class 84 | * handle() to inherit the base class's events (or not as desired). 85 | * If subclasses subclass this handler, they need to override 86 | * getEventHandler() in order for it to return the right concrete 87 | * event handler instance. 88 | */ 89 | class EventHandler : public osgGA::GUIEventHandler 90 | { 91 | public: 92 | EventHandler(OceanTechnique* oceanSurface); 93 | virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*); 94 | /** Get the keyboard and mouse usage of this manipulator.*/ 95 | virtual void getUsage(osg::ApplicationUsage& usage) const; 96 | protected: 97 | OceanTechnique* _oceanSurface; 98 | }; 99 | 100 | /** Virtual constructor for OceanTechnique::EventHandler - override in 101 | * derived classes to return subclass-specific handler if needed. 102 | */ 103 | virtual EventHandler* getEventHandler() 104 | { 105 | if (!_eventHandler.valid()) 106 | _eventHandler = new EventHandler(this); 107 | return _eventHandler.get(); 108 | } 109 | 110 | protected: 111 | virtual ~OceanTechnique(void){}; 112 | 113 | /** 114 | * Add the default resource paths to osgDB::Registry. 115 | * Checks if already present. 116 | * paths: resources/textures and resources/shaders. 117 | */ 118 | virtual void addResourcePaths(void); 119 | 120 | protected: 121 | bool _isDirty; 122 | bool _isAnimating; 123 | osg::ref_ptr _eventHandler; 124 | }; 125 | } 126 | -------------------------------------------------------------------------------- /include/osgOcean/RandUtils: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | 23 | namespace osgOcean 24 | { 25 | /** 26 | * A selection of random number generator utility functions 27 | **/ 28 | namespace RandUtils 29 | { 30 | /** uniformly distributed random int (0 -> RAND_MAX) */ 31 | inline static int myRand( void ) 32 | { 33 | return rand(); 34 | } 35 | 36 | /** uniformly distributed random number (0 -> 1) */ 37 | inline float unitRand( void ) 38 | { 39 | return (float)myRand()/RAND_MAX; 40 | } 41 | 42 | /** uniformly distributed random number (min -> max) */ 43 | inline float rangedRand( float min, float max ) 44 | { 45 | return min + unitRand() * (max - min); 46 | } 47 | 48 | /** Gaussian distributed random number pair 49 | * http://www.taygeta.com/random/gaussian.html 50 | */ 51 | inline void gaussianRand( float& a, float& b ) 52 | { 53 | float x1, x2, length2; 54 | 55 | do { 56 | x1 = rangedRand(-1.f,1.f); 57 | x2 = rangedRand(-1.f,1.f); 58 | length2 = x1 * x1 + x2 * x2; 59 | } 60 | while ( length2 >= 1.f ); 61 | 62 | length2 = sqrt( (-2.f * log( length2 ) ) / length2 ); 63 | 64 | a = x1 * length2; 65 | b = x2 * length2; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /include/osgOcean/ScreenAlignedQuad: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | 23 | namespace osgOcean 24 | { 25 | class OSGOCEAN_EXPORT ScreenAlignedQuad : public osg::Geometry 26 | { 27 | public: 28 | ScreenAlignedQuad( void ); 29 | ScreenAlignedQuad( const osg::Vec3f& corner, const osg::Vec2f& dims, const osg::Vec2s& textureSize ); 30 | ScreenAlignedQuad( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture ); 31 | ScreenAlignedQuad( const ScreenAlignedQuad ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY ); 32 | 33 | virtual void build( const osg::Vec3f& corner, const osg::Vec2f& dims, const osg::Vec2s& textureSize ); 34 | virtual void build( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture ); 35 | 36 | protected: 37 | virtual ~ScreenAlignedQuad(void){}; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /include/osgOcean/ShaderManager: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | namespace osgOcean 26 | { 27 | 28 | class OSGOCEAN_EXPORT ShaderManager 29 | { 30 | private: 31 | typedef std::map GlobalDefinitions; 32 | GlobalDefinitions _globalDefinitions; 33 | bool _shadersEnabled; 34 | 35 | public: 36 | static ShaderManager& instance(); 37 | 38 | /** Set a definition that will be added as a #define to the top of every 39 | * shader loaded through subsequent calls to createProgram() . 40 | */ 41 | template 42 | void setGlobalDefinition(const std::string& name, const T& value) 43 | { 44 | std::ostringstream valStr; 45 | valStr << value; 46 | _globalDefinitions[name] = valStr.str(); 47 | } 48 | 49 | /** Get the value of a global definition that was previously set using 50 | * setGlobalDefinition(). 51 | */ 52 | std::string getGlobalDefiniton(const std::string& name); 53 | 54 | /** Creates a shader program. Will try to load the filenames first, and if 55 | * not found will fall back to using the given shader source strings. 56 | */ 57 | osg::Program* createProgram( const std::string& name, 58 | const std::string& vertexFilename, 59 | const std::string& fragmentFilename, 60 | const std::string& vertexSrc, 61 | const std::string& fragmentSrc ); 62 | 63 | /// Check if shaders are globally enabled or not. 64 | bool areShadersEnabled() const { return _shadersEnabled; } 65 | /// Globally enable or disable shaders for osgOcean. 66 | void enableShaders(bool enable) { _shadersEnabled = enable; } 67 | 68 | private: 69 | // private so clients can't call it, they have to call instance(). 70 | ShaderManager(); 71 | 72 | // No definition, copy and assignment is illegal. 73 | ShaderManager(const ShaderManager&); 74 | ShaderManager& operator=(const ShaderManager&); 75 | 76 | std::string buildGlobalDefinitionsList(const std::string& name); 77 | }; 78 | } 79 | -------------------------------------------------------------------------------- /include/osgOcean/Version: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #ifndef OSGOCEAN_VERSION 19 | #define OSGOCEAN_VERSION 20 | 21 | #include 22 | 23 | extern "C" { 24 | 25 | #define OSGOCEAN_VERSION_MAJOR 1 26 | #define OSGOCEAN_VERSION_MINOR 0 27 | #define OSGOCEAN_VERSION_PATCH 1 28 | 29 | #define OSGOCEAN_VERSION_RELEASE OSGOCEAN_VERSION_PATCH 30 | #define OSGOCEAN_VERSION_REVISION 0 31 | 32 | extern OSGOCEAN_EXPORT const char* osgOceanGetVersion(); 33 | 34 | extern OSGOCEAN_EXPORT const char* osgOceanGetLibraryName(); 35 | 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /include/osgOcean/WaterTrochoids: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace osgOcean 27 | { 28 | class OSGOCEAN_EXPORT WaterTrochoids 29 | { 30 | private: 31 | static const int NUM_WAVES = 16; 32 | 33 | // Wave data structure 34 | struct Wave { 35 | float A; // amplitude 36 | float w; // frequency 37 | float kx,ky; // wave vector components 38 | float kmod; // wave vector module 39 | float phi0; // phase at time 0 40 | float phase; // current phase 41 | float Ainvk; // amplitude/K module 42 | }; 43 | 44 | std::vector _waves; 45 | 46 | // Parameters used for the waves initialization 47 | float _amplitude; // base amplitude (must be <1.0 or they loop over themselves) 48 | float _amplitudeMul; // amplitude multiplier 49 | float _lambda0; // base wavelength 50 | float _lambdaMul; // wavelength multiplier 51 | float _direction; // main waves direction 52 | float _angleDev; // deviation from main direction 53 | 54 | public: 55 | WaterTrochoids( void ); 56 | 57 | WaterTrochoids( const WaterTrochoids& copy ); 58 | 59 | WaterTrochoids(float amplitude, 60 | float amplitudeMul, 61 | float baseWavelen, 62 | float wavelenMul, 63 | float direction, 64 | float angleDev ); 65 | 66 | ~WaterTrochoids( void ); 67 | 68 | // create base waves 69 | void createWaves( void ); 70 | 71 | // update waves 72 | void updateWaves( float time ); 73 | 74 | // pack waves for vertex shader 75 | void packWaves( osg::FloatArray* constant ) const; 76 | 77 | private: 78 | 79 | inline float nextRandomDouble(float lBound, float uBound) 80 | { 81 | static int seed = 0; 82 | srand(seed); 83 | seed++; 84 | return (float)rand()/(float)RAND_MAX * (uBound - lBound) + lBound; 85 | } 86 | }; 87 | } 88 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_dof_combiner_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_dof_combiner_frag[] = 23 | "#extension GL_ARB_texture_rectangle : enable\n" 24 | "\n" 25 | "uniform sampler2DRect osgOcean_FullColourMap; // full resolution image\n" 26 | "uniform sampler2DRect osgOcean_FullDepthMap; // full resolution depth map\n" 27 | "uniform sampler2DRect osgOcean_BlurMap; // downsampled and filtered image\n" 28 | "\n" 29 | "uniform vec2 osgOcean_ScreenRes;\n" 30 | "uniform vec2 osgOcean_ScreenResInv;\n" 31 | "uniform vec2 osgOcean_LowRes;\n" 32 | "\n" 33 | "#define NUM_TAPS 4\n" 34 | "\n" 35 | "// maximum CoC radius and diameter in pixels\n" 36 | "const vec2 vMaxCoC = vec2(5.0,10);\n" 37 | "\n" 38 | "// scale factor for maximum CoC size on low res. image\n" 39 | "const float radiusScale = 0.4;\n" 40 | "\n" 41 | "// contains poisson-distributed positions on the unit circle\n" 42 | "vec2 poisson[8];\n" 43 | "\n" 44 | "void main(void)\n" 45 | "{\n" 46 | " poisson[0] = vec2( 0.0, 0.0);\n" 47 | " poisson[1] = vec2( 0.527837, -0.085868);\n" 48 | " poisson[2] = vec2(-0.040088, 0.536087);\n" 49 | " poisson[3] = vec2(-0.670445, -0.179949);\n" 50 | " poisson[4] = vec2(-0.419418, -0.616039);\n" 51 | " poisson[5] = vec2( 0.440453, -0.639399);\n" 52 | " poisson[6] = vec2(-0.757088, 0.349334);\n" 53 | " poisson[7] = vec2( 0.574619, 0.685879);\n" 54 | "\n" 55 | " // pixel size (1/image resolution) of full resolution image\n" 56 | " vec2 pixelSizeHigh = osgOcean_ScreenResInv;\n" 57 | "\n" 58 | " // pixel size of low resolution image\n" 59 | " vec2 pixelSizeLow = 4.0 * pixelSizeHigh;\n" 60 | "\n" 61 | " vec4 color = texture2DRect( osgOcean_FullColourMap, gl_TexCoord[0].st ); // fetch center tap\n" 62 | " // float centerDepth = color.a; // save its depth\n" 63 | " float centerDepth = texture2DRect( osgOcean_FullDepthMap, gl_TexCoord[0].st ).r; // save its depth\n" 64 | "\n" 65 | " // convert depth into blur radius in pixels\n" 66 | " float discRadius = abs(centerDepth * vMaxCoC.y - vMaxCoC.x);\n" 67 | "\n" 68 | " // compute disc radius on low-res image\n" 69 | " float discRadiusLow = discRadius * radiusScale;\n" 70 | "\n" 71 | " vec4 colorAccum = vec4(0.0);\n" 72 | " float depthAccum = 0.0;\n" 73 | "\n" 74 | " for(int t = 0; t < NUM_TAPS; t++)\n" 75 | " {\n" 76 | " vec2 coordHigh = gl_TexCoord[0].st + ( osgOcean_ScreenRes * (pixelSizeHigh * poisson[t] * discRadius ));\n" 77 | " vec2 coordLow = gl_TexCoord[1].st + ( osgOcean_LowRes * (pixelSizeLow * poisson[t] * discRadiusLow ));\n" 78 | "\n" 79 | " // fetch low-res tap\n" 80 | " vec4 tapLow = texture2DRect( osgOcean_BlurMap, coordLow );\n" 81 | "\n" 82 | " // fetch high-res tap\n" 83 | " vec4 tapHigh = texture2DRect( osgOcean_FullColourMap, coordHigh );\n" 84 | " \n" 85 | " float tapHighDepth = texture2DRect( osgOcean_FullDepthMap, coordHigh ).r;\n" 86 | "\n" 87 | " // put tap blurriness into [0, 1] range\n" 88 | " float tapBlur = abs(tapHighDepth * 2.0 - 1.0);\n" 89 | "\n" 90 | " // mix low- and hi-res taps based on tap blurriness\n" 91 | " vec4 tapColor = mix(tapHigh, tapLow, tapBlur);\n" 92 | "\n" 93 | " // apply leaking reduction: lower weight for taps that are\n" 94 | " // closer than the center tap and in focus\n" 95 | " float tapDepth = (tapHighDepth >= centerDepth) ? 1.0 : abs(tapHighDepth * 2.0 - 1.0);\n" 96 | "\n" 97 | " // accumulate\n" 98 | " colorAccum += tapColor * tapDepth;\n" 99 | " depthAccum += tapDepth;\n" 100 | " }\n" 101 | "\n" 102 | " // normalize and return result\n" 103 | " gl_FragColor = colorAccum / depthAccum;\n" 104 | "}\n" 105 | "\n"; 106 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_dof_combiner_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_dof_combiner_vert[] = 23 | "uniform vec2 osgOcean_ScreenRes;\n" 24 | "uniform vec2 osgOcean_LowRes;\n" 25 | "\n" 26 | "void main( void )\n" 27 | "{\n" 28 | " gl_TexCoord[0] = gl_MultiTexCoord0 * vec4( osgOcean_ScreenRes, 1.0, 1.0 );\n" 29 | " gl_TexCoord[1] = gl_MultiTexCoord0 * vec4( osgOcean_LowRes, 1.0, 1.0 );\n" 30 | "\n" 31 | " gl_Position = ftransform();\n" 32 | "}\n" 33 | "\n"; 34 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_downsample_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_downsample_frag[] = 23 | "#extension GL_ARB_texture_rectangle : enable\n" 24 | "\n" 25 | "uniform sampler2DRect osgOcean_ColorTexture;\n" 26 | "\n" 27 | "const vec2 s1 = vec2(-1, 1);\n" 28 | "const vec2 s2 = vec2( 1, 1);\n" 29 | "const vec2 s3 = vec2( 1,-1);\n" 30 | "const vec2 s4 = vec2(-1,-1);\n" 31 | "\n" 32 | "void main( void )\n" 33 | "{\n" 34 | " vec2 texCoordSample = vec2(0.0);\n" 35 | "\n" 36 | " texCoordSample = gl_TexCoord[0].st + s1;\n" 37 | " vec4 color = texture2DRect(osgOcean_ColorTexture, texCoordSample);\n" 38 | "\n" 39 | " texCoordSample = gl_TexCoord[0].st + s2;\n" 40 | " color += texture2DRect(osgOcean_ColorTexture, texCoordSample);\n" 41 | "\n" 42 | " texCoordSample = gl_TexCoord[0].st + s3;\n" 43 | " color += texture2DRect(osgOcean_ColorTexture, texCoordSample);\n" 44 | "\n" 45 | " texCoordSample = gl_TexCoord[0].st + s4;\n" 46 | " color += texture2DRect(osgOcean_ColorTexture, texCoordSample);\n" 47 | "\n" 48 | " gl_FragColor = color * 0.25;\n" 49 | "}\n"; 50 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_downsample_glare_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_downsample_glare_frag[] = 23 | "#extension GL_ARB_texture_rectangle : enable\n" 24 | "\n" 25 | "uniform sampler2DRect osgOcean_ColorTexture;\n" 26 | "uniform sampler2DRect osgOcean_LuminanceTexture;\n" 27 | "uniform float osgOcean_GlareThreshold;\n" 28 | "\n" 29 | "const vec2 s1 = vec2(-1, 1);\n" 30 | "const vec2 s2 = vec2( 1, 1);\n" 31 | "const vec2 s3 = vec2( 1,-1);\n" 32 | "const vec2 s4 = vec2(-1,-1);\n" 33 | "\n" 34 | "void main( void )\n" 35 | "{\n" 36 | " vec2 texCoordSample = vec2(0.0);\n" 37 | "\n" 38 | " texCoordSample = gl_TexCoord[0].st + s1;\n" 39 | " vec4 color = texture2DRect(osgOcean_ColorTexture, texCoordSample);\n" 40 | " float lum = texture2DRect(osgOcean_LuminanceTexture, texCoordSample).r;\n" 41 | "\n" 42 | " texCoordSample = gl_TexCoord[0].st + s2;\n" 43 | " color += texture2DRect(osgOcean_ColorTexture, texCoordSample);\n" 44 | " lum += texture2DRect(osgOcean_LuminanceTexture, texCoordSample).r;\n" 45 | "\n" 46 | " texCoordSample = gl_TexCoord[0].st + s3;\n" 47 | " color += texture2DRect(osgOcean_ColorTexture, texCoordSample);\n" 48 | " lum += texture2DRect(osgOcean_LuminanceTexture, texCoordSample).r;\n" 49 | "\n" 50 | " texCoordSample = gl_TexCoord[0].st +s4;\n" 51 | " color += texture2DRect(osgOcean_ColorTexture, texCoordSample);\n" 52 | " lum += texture2DRect(osgOcean_LuminanceTexture, texCoordSample).r;\n" 53 | "\n" 54 | " color = color*0.25;\n" 55 | " lum = lum*0.25;\n" 56 | "\n" 57 | " // only want very high luminance values to pass otherwise\n" 58 | " // we get streaks all over the scene\n" 59 | " if(lum >= osgOcean_GlareThreshold)\n" 60 | " gl_FragColor = color;\n" 61 | " else\n" 62 | " gl_FragColor = vec4(0.0);\n" 63 | "}\n"; 64 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_downsample_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_downsample_vert[] = 23 | "void main( void )\n" 24 | "{\n" 25 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 26 | " gl_Position = ftransform();\n" 27 | "}\n"; 28 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_gaussian1_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_gaussian1_frag[] = 23 | "#extension GL_ARB_texture_rectangle : enable\n" 24 | "\n" 25 | "uniform sampler2DRect osgOcean_GaussianTexture;\n" 26 | "\n" 27 | "void main( void )\n" 28 | "{\n" 29 | " vec2 texCoordSample = vec2( 0.0 );\n" 30 | "\n" 31 | " vec4 color = 0.5 * texture2DRect( osgOcean_GaussianTexture, gl_TexCoord[0].st );\n" 32 | "\n" 33 | " texCoordSample.x = gl_TexCoord[0].x;\n" 34 | " texCoordSample.y = gl_TexCoord[0].y + 1.0;\n" 35 | " color += 0.25 * texture2DRect( osgOcean_GaussianTexture, texCoordSample);\n" 36 | "\n" 37 | " texCoordSample.y = gl_TexCoord[0].y - 1.0;\n" 38 | " color += 0.25 * texture2DRect( osgOcean_GaussianTexture, texCoordSample);\n" 39 | "\n" 40 | " gl_FragColor = color;\n" 41 | "}\n"; 42 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_gaussian2_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_gaussian2_frag[] = 23 | "#extension GL_ARB_texture_rectangle : enable\n" 24 | "\n" 25 | "uniform sampler2DRect osgOcean_GaussianTexture;\n" 26 | "\n" 27 | "void main( void )\n" 28 | "{\n" 29 | " vec2 texCoordSample = vec2( 0.0 );\n" 30 | "\n" 31 | " vec4 color = 0.5 * texture2DRect(osgOcean_GaussianTexture, gl_TexCoord[0].st );\n" 32 | "\n" 33 | " texCoordSample.y = gl_TexCoord[0].y;\n" 34 | " texCoordSample.x = gl_TexCoord[0].x + 1.0;\n" 35 | " color += 0.25 * texture2DRect(osgOcean_GaussianTexture, texCoordSample);\n" 36 | "\n" 37 | " texCoordSample.x = gl_TexCoord[0].x - 1.0;\n" 38 | " color += 0.25 * texture2DRect(osgOcean_GaussianTexture, texCoordSample);\n" 39 | "\n" 40 | " gl_FragColor = color;\n" 41 | "}\n"; 42 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_gaussian_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_gaussian_vert[] = 23 | "void main(void)\n" 24 | "{\n" 25 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 26 | " gl_Position = ftransform();\n" 27 | "}\n"; 28 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_glare_composite_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_glare_composite_frag[] = 23 | "#extension GL_ARB_texture_rectangle : enable\n" 24 | "\n" 25 | "uniform sampler2DRect osgOcean_ColorBuffer;\n" 26 | "uniform sampler2DRect osgOcean_StreakBuffer1;\n" 27 | "uniform sampler2DRect osgOcean_StreakBuffer2;\n" 28 | "uniform sampler2DRect osgOcean_StreakBuffer3;\n" 29 | "uniform sampler2DRect osgOcean_StreakBuffer4;\n" 30 | "\n" 31 | "void main(void)\n" 32 | "{\n" 33 | " vec4 fullColor = texture2DRect(osgOcean_ColorBuffer, gl_TexCoord[0].st );\n" 34 | " vec4 streakColor1 = texture2DRect(osgOcean_StreakBuffer1, gl_TexCoord[1].st );\n" 35 | " vec4 streakColor2 = texture2DRect(osgOcean_StreakBuffer2, gl_TexCoord[1].st );\n" 36 | " vec4 streakColor3 = texture2DRect(osgOcean_StreakBuffer3, gl_TexCoord[1].st );\n" 37 | " vec4 streakColor4 = texture2DRect(osgOcean_StreakBuffer4, gl_TexCoord[1].st );\n" 38 | "\n" 39 | " vec4 streak = streakColor1+streakColor2+streakColor3+streakColor4;\n" 40 | "\n" 41 | " gl_FragColor = streak+fullColor; \n" 42 | "}\n"; 43 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_glare_composite_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_glare_composite_vert[] = 23 | "void main(void)\n" 24 | "{\n" 25 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 26 | " gl_TexCoord[1] = gl_MultiTexCoord0 * vec4(0.25,0.25,1.0,1.0);\n" 27 | "\n" 28 | " gl_Position = ftransform();\n" 29 | "}\n"; 30 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_godray_glare_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_godray_glare_frag[] = 23 | "uniform sampler2D osgOcean_GlareTexture;\n" 24 | "\n" 25 | "varying vec3 vIntensity;\n" 26 | "\n" 27 | "void main(void)\n" 28 | "{\n" 29 | " vec3 color = texture2D( osgOcean_GlareTexture, gl_TexCoord[0].st ).rgb;\n" 30 | "\n" 31 | " gl_FragColor = vec4((vIntensity*color.r)*1.5, 1.0 );\n" 32 | "}\n"; 33 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_godray_glare_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_godray_glare_vert[] = 23 | "uniform vec3 osgOcean_Origin;\n" 24 | "uniform vec3 osgOcean_Extinction_c;\n" 25 | "uniform vec3 osgOcean_Eye;\n" 26 | "uniform float osgOcean_Spacing;\n" 27 | "\n" 28 | "varying vec3 vIntensity;\n" 29 | "\n" 30 | "void main(void)\n" 31 | "{\n" 32 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 33 | "\n" 34 | " vec3 worldPos = gl_Vertex.xyz * vec3(osgOcean_Spacing,osgOcean_Spacing,1.0);\n" 35 | " worldPos += osgOcean_Origin;\n" 36 | "\n" 37 | " vec3 extinct = vec3(0.2,0.2,0.2);\n" 38 | "\n" 39 | " float totalDist = length(worldPos-osgOcean_Eye)/3.0;\n" 40 | " vIntensity = exp(-totalDist*osgOcean_Extinction_c);\n" 41 | " vIntensity = clamp(vIntensity, 0.0, 1.0);\n" 42 | "\n" 43 | " gl_Position = gl_ModelViewProjectionMatrix * vec4(worldPos,1.0);\n" 44 | "}\n"; 45 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_godray_screen_blend_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_godray_screen_blend_frag[] = 23 | "uniform sampler2DRect osgOcean_GodRayTexture;\n" 24 | "\n" 25 | "uniform vec3 osgOcean_SunDir;\n" 26 | "uniform vec3 osgOcean_HGg; // Eccentricity constants controls power of forward scattering\n" 27 | "uniform float osgOcean_Intensity; // Intensity tweak for god rays\n" 28 | "uniform vec3 osgOcean_Eye;\n" 29 | "\n" 30 | "varying vec3 vRay;\n" 31 | "\n" 32 | "const float bias = 0.15; // used to hide aliasing\n" 33 | "\n" 34 | "// Mie phase function\n" 35 | "float computeMie(vec3 viewDir, vec3 sunDir)\n" 36 | "{\n" 37 | " float num = osgOcean_HGg.x;\n" 38 | " float den = (osgOcean_HGg.y - osgOcean_HGg.z*dot(sunDir, viewDir));\n" 39 | " den = inversesqrt(den);\n" 40 | "\n" 41 | " float phase = num * (den*den*den);\n" 42 | "\n" 43 | " return phase;\n" 44 | "}\n" 45 | "\n" 46 | "// ----------------------------------------------\n" 47 | "// Main Program\n" 48 | "// ----------------------------------------------\n" 49 | "\n" 50 | "void main( void )\n" 51 | "{\n" 52 | " vec4 shafts;\n" 53 | "\n" 54 | " // average the pixels out a little to hide aliasing\n" 55 | " // TODO: Maybe try a weak blur filter\n" 56 | " shafts += texture2DRect(osgOcean_GodRayTexture, gl_TexCoord[1].xy);\n" 57 | " shafts += texture2DRect(osgOcean_GodRayTexture, gl_TexCoord[1].zw);\n" 58 | " shafts += texture2DRect(osgOcean_GodRayTexture, gl_TexCoord[2].xy);\n" 59 | " shafts += texture2DRect(osgOcean_GodRayTexture, gl_TexCoord[2].zw);\n" 60 | "\n" 61 | " shafts /= 4.0;\n" 62 | "\n" 63 | " vec3 rayNormalised = normalize(vRay-osgOcean_Eye);\n" 64 | "\n" 65 | " float phase = computeMie(rayNormalised, -osgOcean_SunDir);\n" 66 | "\n" 67 | " // Calculate final color, adding a little bias (0.15 here)\n" 68 | " // to hide aliasing\n" 69 | " vec3 colour = (bias+osgOcean_Intensity*shafts.rgb)*phase;\n" 70 | "\n" 71 | " vec3 ray = ( rayNormalised + vec3(1.0) ) / 2.0;\n" 72 | "\n" 73 | " gl_FragColor = vec4(colour, 1.0);\n" 74 | "}\n" 75 | "\n" 76 | "\n" 77 | "\n"; 78 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_godray_screen_blend_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_godray_screen_blend_vert[] = 23 | "varying vec3 vRay;\n" 24 | "\n" 25 | "void main( void )\n" 26 | "{\n" 27 | " gl_Position = gl_Vertex;\n" 28 | "\n" 29 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 30 | "\n" 31 | " gl_TexCoord[1].xy = gl_TexCoord[0].st;\n" 32 | " gl_TexCoord[1].zw = gl_TexCoord[0].st + vec2(1.0, 0.0);\n" 33 | " gl_TexCoord[2].xy = gl_TexCoord[0].st + vec2(1.0, 1.0);\n" 34 | " gl_TexCoord[2].zw = gl_TexCoord[0].st + vec2(0.0, 1.0);\n" 35 | "\n" 36 | " vRay = gl_Normal;\n" 37 | "}\n"; 38 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_godrays_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_godrays_frag[] = 23 | "varying vec3 vIntensity;\n" 24 | "\n" 25 | "void main(void)\n" 26 | "{\n" 27 | " gl_FragColor = vec4(vIntensity,1.0);\n" 28 | "}\n"; 29 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_godrays_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_godrays_vert[] = 23 | "const int NUM_WAVES = 16;\n" 24 | "\n" 25 | "uniform vec3 osgOcean_Origin; // central position of vertices - sun position on water surface\n" 26 | "uniform vec3 osgOcean_Extinction_c; // extinction coefficient\n" 27 | "uniform vec3 osgOcean_Eye; // Eye position in world space\n" 28 | "uniform vec3 osgOcean_SunDir; // sunlight direction\n" 29 | "uniform float osgOcean_Spacing; // spacing between vertices\n" 30 | "uniform float osgOcean_Waves[NUM_WAVES * 5]; // wave constants\n" 31 | "\n" 32 | "varying vec3 vIntensity;\n" 33 | "\n" 34 | "float fastFresnel(vec3 I, vec3 N, float r0)\n" 35 | "{\n" 36 | " return r0 + (1.0-r0) * pow(1.0-dot(I, N), 5.0);\n" 37 | "}\n" 38 | "\n" 39 | "vec3 calculateWaterNormal(float x0, float y0)\n" 40 | "{\n" 41 | " vec3 t1 = vec3(1.0,0.0,0.0);\n" 42 | " vec3 t2 = vec3(0.0,1.0,0.0);\n" 43 | "\n" 44 | " int itr = NUM_WAVES/4;\n" 45 | "\n" 46 | " for (int i = 0, j = 0; i < itr; i++, j += 20)\n" 47 | " {\n" 48 | " vec4 kx = vec4( osgOcean_Waves[j+0], osgOcean_Waves[j+1], osgOcean_Waves[j+2], osgOcean_Waves[j+3] );\n" 49 | " vec4 ky = vec4( osgOcean_Waves[j+4], osgOcean_Waves[j+5], osgOcean_Waves[j+6], osgOcean_Waves[j+7] );\n" 50 | " vec4 Ainvk = vec4( osgOcean_Waves[j+8], osgOcean_Waves[j+9], osgOcean_Waves[j+10], osgOcean_Waves[j+11] );\n" 51 | " vec4 A = vec4( osgOcean_Waves[j+12], osgOcean_Waves[j+13], osgOcean_Waves[j+14], osgOcean_Waves[j+15] );\n" 52 | " vec4 wt = vec4( osgOcean_Waves[j+16], osgOcean_Waves[j+17], osgOcean_Waves[j+18], osgOcean_Waves[j+19] );\n" 53 | " vec4 phase = (kx*x0 + ky*y0 - wt);\n" 54 | " vec4 sinp, cosp;\n" 55 | "\n" 56 | "#if 1\n" 57 | " sinp = sin(phase);\n" 58 | " cosp = cos(phase);\n" 59 | "#else\n" 60 | " sincos(phase, sinp, cosp);\n" 61 | "#endif\n" 62 | "\n" 63 | " // Update tangent vector along x0\n" 64 | " t1.x -= dot(Ainvk, kx*cosp*kx);\n" 65 | " t1.y -= dot(Ainvk, ky*cosp*kx);\n" 66 | " t1.z += dot(A, (-sinp)*(kx));\n" 67 | "\n" 68 | " // Update tangent vector along y0\n" 69 | " t2.x -= dot(Ainvk, kx*cosp*ky);\n" 70 | " t2.y -= dot(Ainvk, ky*cosp*ky);\n" 71 | " t2.z += dot(A, (-sinp)*(ky));\n" 72 | " }\n" 73 | "\n" 74 | " // Calculate and return normal\n" 75 | " return normalize( cross(t1, t2) );\n" 76 | "}\n" 77 | "\n" 78 | "void main(void)\n" 79 | "{\n" 80 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 81 | "\n" 82 | " // Scale and translate the vertex on the water surface\n" 83 | " vec3 worldPos = gl_Vertex.xyz * vec3(osgOcean_Spacing,osgOcean_Spacing,1.0);\n" 84 | " worldPos += osgOcean_Origin;\n" 85 | "\n" 86 | " // Calculate the water normal at this point\n" 87 | " vec3 normal = calculateWaterNormal(worldPos.x, worldPos.y);\n" 88 | "\n" 89 | " // Calculate transmittance\n" 90 | " // BUG: makes intensity too small not sure why.\n" 91 | " float transmittance = 1.0-fastFresnel(-osgOcean_SunDir, normal, 0.0204);\n" 92 | "\n" 93 | " // Extrude bottom vertices along the direction of the refracted\n" 94 | " // sunlight\n" 95 | " if (gl_TexCoord[0].s > 0.0)\n" 96 | " {\n" 97 | " // Calculate refraction vector and extrude polygon\n" 98 | " vec3 refr = refract(osgOcean_SunDir, normal, 0.75);\n" 99 | " worldPos += refr*gl_TexCoord[0].s;\n" 100 | " }\n" 101 | " // Set intensity so that the further away you go from the surface\n" 102 | " float totalDist = gl_TexCoord[0].s + length(worldPos-osgOcean_Eye);\n" 103 | " vIntensity = exp(-totalDist*osgOcean_Extinction_c)*transmittance;\n" 104 | " vIntensity = clamp(vIntensity, 0.0, 0.06);\n" 105 | "\n" 106 | " // Transform position from world to clip space\n" 107 | " gl_Position = gl_ModelViewProjectionMatrix * vec4(worldPos, 1.0 );\n" 108 | " // Tweak z position not to clip shafts very close to the viewer\n" 109 | " gl_Position.z = 0.01;\n" 110 | "}\n"; 111 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_heightmap_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_heightmap_frag[] = 23 | "// osgOcean uniforms\n" 24 | "// -------------------\n" 25 | "uniform float osgOcean_WaterHeight;\n" 26 | "// -------------------\n" 27 | "\n" 28 | "varying vec4 vWorldVertex;\n" 29 | "\n" 30 | "void main(void)\n" 31 | "{\n" 32 | " // Store the water depth\n" 33 | " // maximum possible depth is 500,\n" 34 | " // (a higher water depth value would not have a visible effect anyway)\n" 35 | " gl_FragDepth = clamp((osgOcean_WaterHeight - vWorldVertex.z) / 500.0, 0.0, 1.0);\n" 36 | "\n" 37 | " return;\n" 38 | "}\n"; 39 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_heightmap_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_heightmap_vert[] = 23 | "// osgOcean uniforms\n" 24 | "// -------------------\n" 25 | "uniform float osgOcean_WaterHeight;\n" 26 | "// ------------------\n" 27 | "\n" 28 | "uniform mat4 osg_ViewMatrixInverse;\n" 29 | "uniform mat4 osg_ViewMatrix;\n" 30 | "\n" 31 | "varying vec4 vWorldVertex;\n" 32 | "\n" 33 | "void main(void)\n" 34 | "{\n" 35 | " // Transform the vertex into world space\n" 36 | " vWorldVertex = (osg_ViewMatrixInverse * gl_ModelViewMatrix) * gl_Vertex;\n" 37 | " vWorldVertex.xyzw /= vWorldVertex.w;\n" 38 | "\n" 39 | " // Project the vertex onto the ocean plane\n" 40 | " vec4 projectedVertex = vWorldVertex;\n" 41 | " projectedVertex.z = osgOcean_WaterHeight;\n" 42 | "\n" 43 | " gl_Position = (gl_ProjectionMatrix * osg_ViewMatrix) * projectedVertex;\n" 44 | "\n" 45 | " return;\n" 46 | "}\n"; 47 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_ocean_scene_lispsm_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_ocean_scene_lispsm_vert[] = 23 | "// osgOcean Uniforms\n" 24 | "// -----------------\n" 25 | "uniform mat4 osg_ViewMatrixInverse;\n" 26 | "uniform float osgOcean_WaterHeight;\n" 27 | "uniform vec3 osgOcean_Eye;\n" 28 | "uniform vec3 osgOcean_UnderwaterAttenuation;\n" 29 | "uniform vec4 osgOcean_UnderwaterDiffuse;\n" 30 | "uniform bool osgOcean_EnableUnderwaterScattering;\n" 31 | "// -----------------\n" 32 | "\n" 33 | "varying vec3 vExtinction;\n" 34 | "varying vec3 vInScattering;\n" 35 | "\n" 36 | "varying vec3 vNormal;\n" 37 | "varying vec3 vLightDir;\n" 38 | "varying vec3 vEyeVec;\n" 39 | "varying float vWorldHeight;\n" 40 | "\n" 41 | "void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering )\n" 42 | "{\n" 43 | " float viewDist = length(eye-worldVertex);\n" 44 | " \n" 45 | " float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0);\n" 46 | " \n" 47 | " extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0);\n" 48 | "\n" 49 | " // Need to compute accurate kd constant.\n" 50 | " // const vec3 kd = vec3(0.001, 0.001, 0.001);\n" 51 | " inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001)));\n" 52 | "}\n" 53 | "\n" 54 | "void main(void)\n" 55 | "{\n" 56 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 57 | " gl_Position = ftransform();\n" 58 | " gl_FogFragCoord = gl_Position.z;\n" 59 | " vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;\n" 60 | " gl_ClipVertex = ecPosition; // for reflections\n" 61 | "\n" 62 | " vNormal = gl_NormalMatrix * gl_Normal;\n" 63 | " vLightDir = gl_LightSource[0].position.xyz;\n" 64 | " vEyeVec = -vec3(gl_ModelViewMatrix*gl_Vertex);\n" 65 | "\n" 66 | " vec4 worldVertex = (osg_ViewMatrixInverse*gl_ModelViewMatrix) * gl_Vertex;\n" 67 | "\n" 68 | " if (osgOcean_EnableUnderwaterScattering)\n" 69 | " computeScattering( osgOcean_Eye, worldVertex.xyz, vExtinction, vInScattering);\n" 70 | "\n" 71 | " vWorldHeight = worldVertex.z;\n" 72 | "\n" 73 | " // Generate shadow map coords\n" 74 | " gl_TexCoord[7].s = dot( ecPosition, gl_EyePlaneS[7] );\n" 75 | " gl_TexCoord[7].t = dot( ecPosition, gl_EyePlaneT[7] );\n" 76 | " gl_TexCoord[7].p = dot( ecPosition, gl_EyePlaneR[7] );\n" 77 | " gl_TexCoord[7].q = dot( ecPosition, gl_EyePlaneQ[7] );\n" 78 | "\n" 79 | "}\n"; 80 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_ocean_scene_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_ocean_scene_vert[] = 23 | "// osgOcean Uniforms\n" 24 | "// -----------------\n" 25 | "uniform mat4 osg_ViewMatrixInverse;\n" 26 | "uniform float osgOcean_WaterHeight;\n" 27 | "uniform vec3 osgOcean_Eye;\n" 28 | "uniform vec3 osgOcean_UnderwaterAttenuation;\n" 29 | "uniform vec4 osgOcean_UnderwaterDiffuse;\n" 30 | "uniform bool osgOcean_EnableUnderwaterScattering;\n" 31 | "// -----------------\n" 32 | "\n" 33 | "varying vec3 vExtinction;\n" 34 | "varying vec3 vInScattering;\n" 35 | "\n" 36 | "varying vec3 vNormal;\n" 37 | "varying vec3 vLightDir;\n" 38 | "varying vec3 vEyeVec;\n" 39 | "varying float vWorldHeight;\n" 40 | "\n" 41 | "void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering )\n" 42 | "{\n" 43 | " float viewDist = length(eye-worldVertex);\n" 44 | " \n" 45 | " float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0);\n" 46 | " \n" 47 | " extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0);\n" 48 | "\n" 49 | " // Need to compute accurate kd constant.\n" 50 | " // const vec3 kd = vec3(0.001, 0.001, 0.001);\n" 51 | " inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001)));\n" 52 | "}\n" 53 | "\n" 54 | "void main(void)\n" 55 | "{\n" 56 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 57 | " gl_Position = ftransform();\n" 58 | " gl_FogFragCoord = gl_Position.z;\n" 59 | " gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; // for reflections\n" 60 | "\n" 61 | " vNormal = gl_NormalMatrix * gl_Normal;\n" 62 | " vLightDir = gl_LightSource[osgOcean_LightID].position.xyz;\n" 63 | " vEyeVec = -vec3(gl_ModelViewMatrix*gl_Vertex);\n" 64 | "\n" 65 | " vec4 worldVertex = (osg_ViewMatrixInverse*gl_ModelViewMatrix) * gl_Vertex;\n" 66 | "\n" 67 | " if (osgOcean_EnableUnderwaterScattering)\n" 68 | " computeScattering( osgOcean_Eye, worldVertex.xyz, vExtinction, vInScattering);\n" 69 | "\n" 70 | " vWorldHeight = worldVertex.z;\n" 71 | "}\n"; 72 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_silt_points_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_silt_points_frag[] = 23 | "uniform sampler2D osgOcean_BaseTexture;\n" 24 | "varying vec4 colour;\n" 25 | "\n" 26 | "void main (void)\n" 27 | "{\n" 28 | " gl_FragColor = colour * texture2D( osgOcean_BaseTexture, gl_TexCoord[0].xy);\n" 29 | "}\n"; 30 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_silt_points_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_silt_points_vert[] = 23 | "uniform float osgOcean_InversePeriod;\n" 24 | "uniform vec4 osgOcean_ParticleColour;\n" 25 | "uniform float osgOcean_ParticleSize;\n" 26 | "\n" 27 | "uniform float osg_SimulationTime;\n" 28 | "\n" 29 | "varying vec4 colour;\n" 30 | "\n" 31 | "void main(void)\n" 32 | "{\n" 33 | " float startTime = gl_MultiTexCoord1.x;\n" 34 | "\n" 35 | " vec4 v_current = gl_Vertex;\n" 36 | "\n" 37 | " float disp = (osg_SimulationTime - startTime)*osgOcean_InversePeriod;\n" 38 | "\n" 39 | " vec3 direction = sign(gl_Normal);\n" 40 | "\n" 41 | " v_current.x = direction.x * fract( disp + gl_Vertex.x );\n" 42 | " v_current.y = direction.y * fract( disp + gl_Vertex.y );\n" 43 | " v_current.z = direction.z * fract( disp + gl_Vertex.z );\n" 44 | "\n" 45 | " colour = osgOcean_ParticleColour;\n" 46 | "\n" 47 | " gl_Position = gl_ModelViewProjectionMatrix * v_current;\n" 48 | "\n" 49 | " float pointSize = abs(1280.0*osgOcean_ParticleSize / gl_Position.w);\n" 50 | "\n" 51 | " gl_PointSize = ceil(pointSize);\n" 52 | "\n" 53 | " colour.a = 0.05+(pointSize*pointSize)/(gl_PointSize*gl_PointSize);\n" 54 | "\n" 55 | " gl_ClipVertex = v_current;\n" 56 | "}\n"; 57 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_silt_quads_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_silt_quads_frag[] = 23 | "uniform sampler2D osgOcean_BaseTexture;\n" 24 | "varying vec2 texCoord;\n" 25 | "varying vec4 colour;\n" 26 | "\n" 27 | "void main (void)\n" 28 | "{\n" 29 | " gl_FragColor = colour * texture2D( osgOcean_BaseTexture, texCoord);\n" 30 | "}\n"; 31 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_silt_quads_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_silt_quads_vert[] = 23 | "uniform vec4 osgOcean_ParticleColour;\n" 24 | "\n" 25 | "uniform float osgOcean_InversePeriod;\n" 26 | "uniform float osgOcean_ParticleSize;\n" 27 | "uniform float osg_SimulationTime;\n" 28 | "uniform float osg_DeltaSimulationTime;\n" 29 | "\n" 30 | "varying vec4 colour;\n" 31 | "varying vec2 texCoord;\n" 32 | "\n" 33 | "void main(void)\n" 34 | "{\n" 35 | " float startTime = gl_MultiTexCoord1.x;\n" 36 | " texCoord = gl_MultiTexCoord0.xy;\n" 37 | "\n" 38 | " float disp = (osg_SimulationTime - startTime)*osgOcean_InversePeriod;\n" 39 | "\n" 40 | " vec4 v_previous = gl_Vertex;\n" 41 | "\n" 42 | " vec3 direction = sign(gl_Normal);\n" 43 | "\n" 44 | " v_previous.x = direction.x * fract( disp + gl_Vertex.x );\n" 45 | " v_previous.y = direction.y * fract( disp + gl_Vertex.y );\n" 46 | " v_previous.z = direction.z * fract( disp + gl_Vertex.z );\n" 47 | "\n" 48 | " vec4 v_current = v_previous;\n" 49 | "\n" 50 | " v_current.x += ( osg_DeltaSimulationTime * osgOcean_InversePeriod );\n" 51 | " v_current.y += ( osg_DeltaSimulationTime * osgOcean_InversePeriod );\n" 52 | " v_current.z += ( osg_DeltaSimulationTime * osgOcean_InversePeriod );\n" 53 | "\n" 54 | " colour = osgOcean_ParticleColour;\n" 55 | "\n" 56 | " vec4 v1 = gl_ModelViewMatrix * v_current;\n" 57 | " vec4 v2 = gl_ModelViewMatrix * v_previous;\n" 58 | "\n" 59 | " vec3 dv = v2.xyz - v1.xyz;\n" 60 | "\n" 61 | " vec2 dv_normalized = normalize(dv.xy);\n" 62 | " dv.xy += dv_normalized * osgOcean_ParticleSize;\n" 63 | " vec2 dp = vec2( -dv_normalized.y, dv_normalized.x ) * osgOcean_ParticleSize;\n" 64 | "\n" 65 | " float area = length(dv.xy);\n" 66 | " colour.a = 0.05+(osgOcean_ParticleSize)/area;\n" 67 | "\n" 68 | " v1.xyz += dv*texCoord.y;\n" 69 | " v1.xy += dp*texCoord.x;\n" 70 | "\n" 71 | " gl_Position = gl_ProjectionMatrix * v1;\n" 72 | " gl_Position.z = 0.01;\n" 73 | " gl_ClipVertex = v1;\n" 74 | "}\n"; 75 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_streak_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_streak_frag[] = 23 | "#extension GL_ARB_texture_rectangle : enable\n" 24 | "\n" 25 | "#define NUM_SAMPLES 4\n" 26 | "\n" 27 | "uniform sampler2DRect osgOcean_Buffer;\n" 28 | "uniform vec2 osgOcean_Direction;\n" 29 | "uniform float osgOcean_Attenuation;\n" 30 | "uniform float osgOcean_Pass;\n" 31 | "\n" 32 | "void main(void)\n" 33 | "{\n" 34 | " vec2 sampleCoord = vec2(0.0);\n" 35 | " vec3 cOut = vec3(0.0);\n" 36 | "\n" 37 | " // sample weight = a^(b*s)\n" 38 | " // a = attenuation\n" 39 | " // b = 4^(pass-1)\n" 40 | " // s = sample number\n" 41 | "\n" 42 | " vec2 pxSize = vec2(0.5);\n" 43 | "\n" 44 | " float b = pow( float(NUM_SAMPLES), float(osgOcean_Pass));\n" 45 | " float sf = 0.0;\n" 46 | "\n" 47 | " for (int s = 0; s < NUM_SAMPLES; s++)\n" 48 | " {\n" 49 | " sf = float(s);\n" 50 | " float weight = pow(osgOcean_Attenuation, b * sf);\n" 51 | " sampleCoord = gl_TexCoord[0].st + (osgOcean_Direction * b * vec2(sf) * pxSize);\n" 52 | " cOut += clamp(weight,0.0,1.0) * texture2DRect(osgOcean_Buffer, sampleCoord).rgb;\n" 53 | " }\n" 54 | "\n" 55 | " vec3 streak = clamp(cOut, 0.0, 1.0);\n" 56 | "\n" 57 | " gl_FragColor = vec4(streak,1.0);\n" 58 | "}\n"; 59 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_streak_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_streak_vert[] = 23 | "\n" 24 | "void main(void)\n" 25 | "{\n" 26 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 27 | " gl_Position = ftransform();\n" 28 | "}\n"; 29 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_water_distortion_frag.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_water_distortion_frag[] = 23 | "// Based on Jon Kennedy's heat haze shader\n" 24 | "// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.\n" 25 | "\n" 26 | "uniform float osgOcean_Frequency;\n" 27 | "uniform float osgOcean_Offset;\n" 28 | "uniform float osgOcean_Speed;\n" 29 | "uniform vec2 osgOcean_ScreenRes;\n" 30 | "\n" 31 | "uniform sampler2DRect osgOcean_FrameBuffer;\n" 32 | "\n" 33 | "varying vec4 vEyePos;\n" 34 | "\n" 35 | "void main (void)\n" 36 | "{\n" 37 | " vec2 index;\n" 38 | "\n" 39 | " // perform the div by w to put the texture into screen space\n" 40 | " float recipW = 1.0 / vEyePos.w;\n" 41 | " vec2 eye = vEyePos.xy * vec2(recipW);\n" 42 | "\n" 43 | " float blend = max(1.0 - eye.y, 0.0);\n" 44 | "\n" 45 | " // calc the wobble\n" 46 | " // index.s = eye.x ;\n" 47 | " index.s = eye.x + blend * sin( osgOcean_Frequency * 5.0 * eye.x + osgOcean_Offset * osgOcean_Speed ) * 0.004;\n" 48 | " index.t = eye.y + blend * sin( osgOcean_Frequency * 5.0 * eye.y + osgOcean_Offset * osgOcean_Speed ) * 0.004;\n" 49 | "\n" 50 | " // scale and shift so we're in the range 0-1\n" 51 | " index.s = index.s * 0.5 + 0.5;\n" 52 | " index.t = index.t * 0.5 + 0.5;\n" 53 | "\n" 54 | " vec2 recipRes = vec2(1.0/osgOcean_ScreenRes.x, 1.0/osgOcean_ScreenRes.y);\n" 55 | "\n" 56 | " index.s = clamp(index.s, 0.0, 1.0 - recipRes.x);\n" 57 | " index.t = clamp(index.t, 0.0, 1.0 - recipRes.y);\n" 58 | "\n" 59 | " // scale the texture so we just see the rendered framebuffer\n" 60 | " index.s = index.s * osgOcean_ScreenRes.x;\n" 61 | " index.t = index.t * osgOcean_ScreenRes.y;\n" 62 | "\n" 63 | " vec3 RefractionColor = vec3( texture2DRect( osgOcean_FrameBuffer, index ) );\n" 64 | "\n" 65 | " gl_FragColor = vec4( RefractionColor, 1.0 );\n" 66 | " //gl_FragColor = texture2DRect( osgOcean_FrameBuffer, gl_TexCoord[0].st );\n" 67 | "}\n"; 68 | -------------------------------------------------------------------------------- /include/osgOcean/shaders/osgOcean_water_distortion_vert.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | 22 | static const char osgOcean_water_distortion_vert[] = 23 | "varying vec4 vEyePos;\n" 24 | "\n" 25 | "void main(void)\n" 26 | "{\n" 27 | " gl_TexCoord[0] = gl_MultiTexCoord0;\n" 28 | " vEyePos = gl_ModelViewProjectionMatrix * gl_Vertex;\n" 29 | " gl_Position = ftransform();\n" 30 | "}\n"; 31 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_dof_combiner.frag: -------------------------------------------------------------------------------- 1 | #extension GL_ARB_texture_rectangle : enable 2 | 3 | uniform sampler2DRect osgOcean_FullColourMap; // full resolution image 4 | uniform sampler2DRect osgOcean_FullDepthMap; // full resolution depth map 5 | uniform sampler2DRect osgOcean_BlurMap; // downsampled and filtered image 6 | 7 | uniform vec2 osgOcean_ScreenRes; 8 | uniform vec2 osgOcean_ScreenResInv; 9 | uniform vec2 osgOcean_LowRes; 10 | 11 | #define NUM_TAPS 4 12 | 13 | // maximum CoC radius and diameter in pixels 14 | const vec2 vMaxCoC = vec2(5.0,10); 15 | 16 | // scale factor for maximum CoC size on low res. image 17 | const float radiusScale = 0.4; 18 | 19 | // contains poisson-distributed positions on the unit circle 20 | vec2 poisson[8]; 21 | 22 | void main(void) 23 | { 24 | poisson[0] = vec2( 0.0, 0.0); 25 | poisson[1] = vec2( 0.527837, -0.085868); 26 | poisson[2] = vec2(-0.040088, 0.536087); 27 | poisson[3] = vec2(-0.670445, -0.179949); 28 | poisson[4] = vec2(-0.419418, -0.616039); 29 | poisson[5] = vec2( 0.440453, -0.639399); 30 | poisson[6] = vec2(-0.757088, 0.349334); 31 | poisson[7] = vec2( 0.574619, 0.685879); 32 | 33 | // pixel size (1/image resolution) of full resolution image 34 | vec2 pixelSizeHigh = osgOcean_ScreenResInv; 35 | 36 | // pixel size of low resolution image 37 | vec2 pixelSizeLow = 4.0 * pixelSizeHigh; 38 | 39 | vec4 color = texture2DRect( osgOcean_FullColourMap, gl_TexCoord[0].st ); // fetch center tap 40 | // float centerDepth = color.a; // save its depth 41 | float centerDepth = texture2DRect( osgOcean_FullDepthMap, gl_TexCoord[0].st ).r; // save its depth 42 | 43 | // convert depth into blur radius in pixels 44 | float discRadius = abs(centerDepth * vMaxCoC.y - vMaxCoC.x); 45 | 46 | // compute disc radius on low-res image 47 | float discRadiusLow = discRadius * radiusScale; 48 | 49 | vec4 colorAccum = vec4(0.0); 50 | float depthAccum = 0.0; 51 | 52 | for(int t = 0; t < NUM_TAPS; t++) 53 | { 54 | vec2 coordHigh = gl_TexCoord[0].st + ( osgOcean_ScreenRes * (pixelSizeHigh * poisson[t] * discRadius )); 55 | vec2 coordLow = gl_TexCoord[1].st + ( osgOcean_LowRes * (pixelSizeLow * poisson[t] * discRadiusLow )); 56 | 57 | // fetch low-res tap 58 | vec4 tapLow = texture2DRect( osgOcean_BlurMap, coordLow ); 59 | 60 | // fetch high-res tap 61 | vec4 tapHigh = texture2DRect( osgOcean_FullColourMap, coordHigh ); 62 | 63 | float tapHighDepth = texture2DRect( osgOcean_FullDepthMap, coordHigh ).r; 64 | 65 | // put tap blurriness into [0, 1] range 66 | float tapBlur = abs(tapHighDepth * 2.0 - 1.0); 67 | 68 | // mix low- and hi-res taps based on tap blurriness 69 | vec4 tapColor = mix(tapHigh, tapLow, tapBlur); 70 | 71 | // apply leaking reduction: lower weight for taps that are 72 | // closer than the center tap and in focus 73 | float tapDepth = (tapHighDepth >= centerDepth) ? 1.0 : abs(tapHighDepth * 2.0 - 1.0); 74 | 75 | // accumulate 76 | colorAccum += tapColor * tapDepth; 77 | depthAccum += tapDepth; 78 | } 79 | 80 | // normalize and return result 81 | gl_FragColor = colorAccum / depthAccum; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_dof_combiner.vert: -------------------------------------------------------------------------------- 1 | uniform vec2 osgOcean_ScreenRes; 2 | uniform vec2 osgOcean_LowRes; 3 | 4 | void main( void ) 5 | { 6 | gl_TexCoord[0] = gl_MultiTexCoord0 * vec4( osgOcean_ScreenRes, 1.0, 1.0 ); 7 | gl_TexCoord[1] = gl_MultiTexCoord0 * vec4( osgOcean_LowRes, 1.0, 1.0 ); 8 | 9 | gl_Position = ftransform(); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_downsample.frag: -------------------------------------------------------------------------------- 1 | #extension GL_ARB_texture_rectangle : enable 2 | 3 | uniform sampler2DRect osgOcean_ColorTexture; 4 | 5 | const vec2 s1 = vec2(-1, 1); 6 | const vec2 s2 = vec2( 1, 1); 7 | const vec2 s3 = vec2( 1,-1); 8 | const vec2 s4 = vec2(-1,-1); 9 | 10 | void main( void ) 11 | { 12 | vec2 texCoordSample = vec2(0.0); 13 | 14 | texCoordSample = gl_TexCoord[0].st + s1; 15 | vec4 color = texture2DRect(osgOcean_ColorTexture, texCoordSample); 16 | 17 | texCoordSample = gl_TexCoord[0].st + s2; 18 | color += texture2DRect(osgOcean_ColorTexture, texCoordSample); 19 | 20 | texCoordSample = gl_TexCoord[0].st + s3; 21 | color += texture2DRect(osgOcean_ColorTexture, texCoordSample); 22 | 23 | texCoordSample = gl_TexCoord[0].st + s4; 24 | color += texture2DRect(osgOcean_ColorTexture, texCoordSample); 25 | 26 | gl_FragColor = color * 0.25; 27 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_downsample.vert: -------------------------------------------------------------------------------- 1 | void main( void ) 2 | { 3 | gl_TexCoord[0] = gl_MultiTexCoord0; 4 | gl_Position = ftransform(); 5 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_downsample_glare.frag: -------------------------------------------------------------------------------- 1 | #extension GL_ARB_texture_rectangle : enable 2 | 3 | uniform sampler2DRect osgOcean_ColorTexture; 4 | uniform sampler2DRect osgOcean_LuminanceTexture; 5 | uniform float osgOcean_GlareThreshold; 6 | 7 | const vec2 s1 = vec2(-1, 1); 8 | const vec2 s2 = vec2( 1, 1); 9 | const vec2 s3 = vec2( 1,-1); 10 | const vec2 s4 = vec2(-1,-1); 11 | 12 | void main( void ) 13 | { 14 | vec2 texCoordSample = vec2(0.0); 15 | 16 | texCoordSample = gl_TexCoord[0].st + s1; 17 | vec4 color = texture2DRect(osgOcean_ColorTexture, texCoordSample); 18 | float lum = texture2DRect(osgOcean_LuminanceTexture, texCoordSample).r; 19 | 20 | texCoordSample = gl_TexCoord[0].st + s2; 21 | color += texture2DRect(osgOcean_ColorTexture, texCoordSample); 22 | lum += texture2DRect(osgOcean_LuminanceTexture, texCoordSample).r; 23 | 24 | texCoordSample = gl_TexCoord[0].st + s3; 25 | color += texture2DRect(osgOcean_ColorTexture, texCoordSample); 26 | lum += texture2DRect(osgOcean_LuminanceTexture, texCoordSample).r; 27 | 28 | texCoordSample = gl_TexCoord[0].st +s4; 29 | color += texture2DRect(osgOcean_ColorTexture, texCoordSample); 30 | lum += texture2DRect(osgOcean_LuminanceTexture, texCoordSample).r; 31 | 32 | color = color*0.25; 33 | lum = lum*0.25; 34 | 35 | // only want very high luminance values to pass otherwise 36 | // we get streaks all over the scene 37 | if(lum >= osgOcean_GlareThreshold) 38 | gl_FragColor = color; 39 | else 40 | gl_FragColor = vec4(0.0); 41 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_gaussian.vert: -------------------------------------------------------------------------------- 1 | void main(void) 2 | { 3 | gl_TexCoord[0] = gl_MultiTexCoord0; 4 | gl_Position = ftransform(); 5 | } 6 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_gaussian1.frag: -------------------------------------------------------------------------------- 1 | #extension GL_ARB_texture_rectangle : enable 2 | 3 | uniform sampler2DRect osgOcean_GaussianTexture; 4 | 5 | void main( void ) 6 | { 7 | vec2 texCoordSample = vec2( 0.0 ); 8 | 9 | vec4 color = 0.5 * texture2DRect( osgOcean_GaussianTexture, gl_TexCoord[0].st ); 10 | 11 | texCoordSample.x = gl_TexCoord[0].x; 12 | texCoordSample.y = gl_TexCoord[0].y + 1.0; 13 | color += 0.25 * texture2DRect( osgOcean_GaussianTexture, texCoordSample); 14 | 15 | texCoordSample.y = gl_TexCoord[0].y - 1.0; 16 | color += 0.25 * texture2DRect( osgOcean_GaussianTexture, texCoordSample); 17 | 18 | gl_FragColor = color; 19 | } 20 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_gaussian2.frag: -------------------------------------------------------------------------------- 1 | #extension GL_ARB_texture_rectangle : enable 2 | 3 | uniform sampler2DRect osgOcean_GaussianTexture; 4 | 5 | void main( void ) 6 | { 7 | vec2 texCoordSample = vec2( 0.0 ); 8 | 9 | vec4 color = 0.5 * texture2DRect(osgOcean_GaussianTexture, gl_TexCoord[0].st ); 10 | 11 | texCoordSample.y = gl_TexCoord[0].y; 12 | texCoordSample.x = gl_TexCoord[0].x + 1.0; 13 | color += 0.25 * texture2DRect(osgOcean_GaussianTexture, texCoordSample); 14 | 15 | texCoordSample.x = gl_TexCoord[0].x - 1.0; 16 | color += 0.25 * texture2DRect(osgOcean_GaussianTexture, texCoordSample); 17 | 18 | gl_FragColor = color; 19 | } 20 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_glare_composite.frag: -------------------------------------------------------------------------------- 1 | #extension GL_ARB_texture_rectangle : enable 2 | 3 | uniform sampler2DRect osgOcean_ColorBuffer; 4 | uniform sampler2DRect osgOcean_StreakBuffer1; 5 | uniform sampler2DRect osgOcean_StreakBuffer2; 6 | uniform sampler2DRect osgOcean_StreakBuffer3; 7 | uniform sampler2DRect osgOcean_StreakBuffer4; 8 | 9 | void main(void) 10 | { 11 | vec4 fullColor = texture2DRect(osgOcean_ColorBuffer, gl_TexCoord[0].st ); 12 | vec4 streakColor1 = texture2DRect(osgOcean_StreakBuffer1, gl_TexCoord[1].st ); 13 | vec4 streakColor2 = texture2DRect(osgOcean_StreakBuffer2, gl_TexCoord[1].st ); 14 | vec4 streakColor3 = texture2DRect(osgOcean_StreakBuffer3, gl_TexCoord[1].st ); 15 | vec4 streakColor4 = texture2DRect(osgOcean_StreakBuffer4, gl_TexCoord[1].st ); 16 | 17 | vec4 streak = streakColor1+streakColor2+streakColor3+streakColor4; 18 | 19 | gl_FragColor = streak+fullColor; 20 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_glare_composite.vert: -------------------------------------------------------------------------------- 1 | void main(void) 2 | { 3 | gl_TexCoord[0] = gl_MultiTexCoord0; 4 | gl_TexCoord[1] = gl_MultiTexCoord0 * vec4(0.25,0.25,1.0,1.0); 5 | 6 | gl_Position = ftransform(); 7 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_godray_glare.frag: -------------------------------------------------------------------------------- 1 | uniform sampler2D osgOcean_GlareTexture; 2 | 3 | varying vec3 vIntensity; 4 | 5 | void main(void) 6 | { 7 | vec3 color = texture2D( osgOcean_GlareTexture, gl_TexCoord[0].st ).rgb; 8 | 9 | gl_FragColor = vec4((vIntensity*color.r)*1.5, 1.0 ); 10 | } 11 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_godray_glare.vert: -------------------------------------------------------------------------------- 1 | uniform vec3 osgOcean_Origin; 2 | uniform vec3 osgOcean_Extinction_c; 3 | uniform vec3 osgOcean_Eye; 4 | uniform float osgOcean_Spacing; 5 | 6 | varying vec3 vIntensity; 7 | 8 | void main(void) 9 | { 10 | gl_TexCoord[0] = gl_MultiTexCoord0; 11 | 12 | vec3 worldPos = gl_Vertex.xyz * vec3(osgOcean_Spacing,osgOcean_Spacing,1.0); 13 | worldPos += osgOcean_Origin; 14 | 15 | vec3 extinct = vec3(0.2,0.2,0.2); 16 | 17 | float totalDist = length(worldPos-osgOcean_Eye)/3.0; 18 | vIntensity = exp(-totalDist*osgOcean_Extinction_c); 19 | vIntensity = clamp(vIntensity, 0.0, 1.0); 20 | 21 | gl_Position = gl_ModelViewProjectionMatrix * vec4(worldPos,1.0); 22 | } 23 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_godray_screen_blend.frag: -------------------------------------------------------------------------------- 1 | uniform sampler2DRect osgOcean_GodRayTexture; 2 | 3 | uniform vec3 osgOcean_SunDir; 4 | uniform vec3 osgOcean_HGg; // Eccentricity constants controls power of forward scattering 5 | uniform float osgOcean_Intensity; // Intensity tweak for god rays 6 | uniform vec3 osgOcean_Eye; 7 | 8 | varying vec3 vRay; 9 | 10 | const float bias = 0.15; // used to hide aliasing 11 | 12 | // Mie phase function 13 | float computeMie(vec3 viewDir, vec3 sunDir) 14 | { 15 | float num = osgOcean_HGg.x; 16 | float den = (osgOcean_HGg.y - osgOcean_HGg.z*dot(sunDir, viewDir)); 17 | den = inversesqrt(den); 18 | 19 | float phase = num * (den*den*den); 20 | 21 | return phase; 22 | } 23 | 24 | // ---------------------------------------------- 25 | // Main Program 26 | // ---------------------------------------------- 27 | 28 | void main( void ) 29 | { 30 | vec4 shafts; 31 | 32 | // average the pixels out a little to hide aliasing 33 | // TODO: Maybe try a weak blur filter 34 | shafts += texture2DRect(osgOcean_GodRayTexture, gl_TexCoord[1].xy); 35 | shafts += texture2DRect(osgOcean_GodRayTexture, gl_TexCoord[1].zw); 36 | shafts += texture2DRect(osgOcean_GodRayTexture, gl_TexCoord[2].xy); 37 | shafts += texture2DRect(osgOcean_GodRayTexture, gl_TexCoord[2].zw); 38 | 39 | shafts /= 4.0; 40 | 41 | vec3 rayNormalised = normalize(vRay-osgOcean_Eye); 42 | 43 | float phase = computeMie(rayNormalised, -osgOcean_SunDir); 44 | 45 | // Calculate final color, adding a little bias (0.15 here) 46 | // to hide aliasing 47 | vec3 colour = (bias+osgOcean_Intensity*shafts.rgb)*phase; 48 | 49 | vec3 ray = ( rayNormalised + vec3(1.0) ) / 2.0; 50 | 51 | gl_FragColor = vec4(colour, 1.0); 52 | } 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_godray_screen_blend.vert: -------------------------------------------------------------------------------- 1 | varying vec3 vRay; 2 | 3 | void main( void ) 4 | { 5 | gl_Position = gl_Vertex; 6 | 7 | gl_TexCoord[0] = gl_MultiTexCoord0; 8 | 9 | gl_TexCoord[1].xy = gl_TexCoord[0].st; 10 | gl_TexCoord[1].zw = gl_TexCoord[0].st + vec2(1.0, 0.0); 11 | gl_TexCoord[2].xy = gl_TexCoord[0].st + vec2(1.0, 1.0); 12 | gl_TexCoord[2].zw = gl_TexCoord[0].st + vec2(0.0, 1.0); 13 | 14 | vRay = gl_Normal; 15 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_godrays.frag: -------------------------------------------------------------------------------- 1 | varying vec3 vIntensity; 2 | 3 | void main(void) 4 | { 5 | gl_FragColor = vec4(vIntensity,1.0); 6 | } 7 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_godrays.vert: -------------------------------------------------------------------------------- 1 | const int NUM_WAVES = 16; 2 | 3 | uniform vec3 osgOcean_Origin; // central position of vertices - sun position on water surface 4 | uniform vec3 osgOcean_Extinction_c; // extinction coefficient 5 | uniform vec3 osgOcean_Eye; // Eye position in world space 6 | uniform vec3 osgOcean_SunDir; // sunlight direction 7 | uniform float osgOcean_Spacing; // spacing between vertices 8 | uniform float osgOcean_Waves[NUM_WAVES * 5]; // wave constants 9 | 10 | varying vec3 vIntensity; 11 | 12 | float fastFresnel(vec3 I, vec3 N, float r0) 13 | { 14 | return r0 + (1.0-r0) * pow(1.0-dot(I, N), 5.0); 15 | } 16 | 17 | vec3 calculateWaterNormal(float x0, float y0) 18 | { 19 | vec3 t1 = vec3(1.0,0.0,0.0); 20 | vec3 t2 = vec3(0.0,1.0,0.0); 21 | 22 | int itr = NUM_WAVES/4; 23 | 24 | for (int i = 0, j = 0; i < itr; i++, j += 20) 25 | { 26 | vec4 kx = vec4( osgOcean_Waves[j+0], osgOcean_Waves[j+1], osgOcean_Waves[j+2], osgOcean_Waves[j+3] ); 27 | vec4 ky = vec4( osgOcean_Waves[j+4], osgOcean_Waves[j+5], osgOcean_Waves[j+6], osgOcean_Waves[j+7] ); 28 | vec4 Ainvk = vec4( osgOcean_Waves[j+8], osgOcean_Waves[j+9], osgOcean_Waves[j+10], osgOcean_Waves[j+11] ); 29 | vec4 A = vec4( osgOcean_Waves[j+12], osgOcean_Waves[j+13], osgOcean_Waves[j+14], osgOcean_Waves[j+15] ); 30 | vec4 wt = vec4( osgOcean_Waves[j+16], osgOcean_Waves[j+17], osgOcean_Waves[j+18], osgOcean_Waves[j+19] ); 31 | vec4 phase = (kx*x0 + ky*y0 - wt); 32 | vec4 sinp, cosp; 33 | 34 | #if 1 35 | sinp = sin(phase); 36 | cosp = cos(phase); 37 | #else 38 | sincos(phase, sinp, cosp); 39 | #endif 40 | 41 | // Update tangent vector along x0 42 | t1.x -= dot(Ainvk, kx*cosp*kx); 43 | t1.y -= dot(Ainvk, ky*cosp*kx); 44 | t1.z += dot(A, (-sinp)*(kx)); 45 | 46 | // Update tangent vector along y0 47 | t2.x -= dot(Ainvk, kx*cosp*ky); 48 | t2.y -= dot(Ainvk, ky*cosp*ky); 49 | t2.z += dot(A, (-sinp)*(ky)); 50 | } 51 | 52 | // Calculate and return normal 53 | return normalize( cross(t1, t2) ); 54 | } 55 | 56 | void main(void) 57 | { 58 | gl_TexCoord[0] = gl_MultiTexCoord0; 59 | 60 | // Scale and translate the vertex on the water surface 61 | vec3 worldPos = gl_Vertex.xyz * vec3(osgOcean_Spacing,osgOcean_Spacing,1.0); 62 | worldPos += osgOcean_Origin; 63 | 64 | // Calculate the water normal at this point 65 | vec3 normal = calculateWaterNormal(worldPos.x, worldPos.y); 66 | 67 | // Calculate transmittance 68 | // BUG: makes intensity too small not sure why. 69 | float transmittance = 1.0-fastFresnel(-osgOcean_SunDir, normal, 0.0204); 70 | 71 | // Extrude bottom vertices along the direction of the refracted 72 | // sunlight 73 | if (gl_TexCoord[0].s > 0.0) 74 | { 75 | // Calculate refraction vector and extrude polygon 76 | vec3 refr = refract(osgOcean_SunDir, normal, 0.75); 77 | worldPos += refr*gl_TexCoord[0].s; 78 | } 79 | // Set intensity so that the further away you go from the surface 80 | float totalDist = gl_TexCoord[0].s + length(worldPos-osgOcean_Eye); 81 | vIntensity = exp(-totalDist*osgOcean_Extinction_c)*transmittance; 82 | vIntensity = clamp(vIntensity, 0.0, 0.06); 83 | 84 | // Transform position from world to clip space 85 | gl_Position = gl_ModelViewProjectionMatrix * vec4(worldPos, 1.0 ); 86 | // Tweak z position not to clip shafts very close to the viewer 87 | gl_Position.z = 0.01; 88 | } 89 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_heightmap.frag: -------------------------------------------------------------------------------- 1 | // osgOcean uniforms 2 | // ------------------- 3 | uniform float osgOcean_WaterHeight; 4 | // ------------------- 5 | 6 | varying vec4 vWorldVertex; 7 | 8 | void main(void) 9 | { 10 | // Store the water depth 11 | // maximum possible depth is 500, 12 | // (a higher water depth value would not have a visible effect anyway) 13 | gl_FragDepth = clamp((osgOcean_WaterHeight - vWorldVertex.z) / 500.0, 0.0, 1.0); 14 | 15 | return; 16 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_heightmap.vert: -------------------------------------------------------------------------------- 1 | // osgOcean uniforms 2 | // ------------------- 3 | uniform float osgOcean_WaterHeight; 4 | // ------------------ 5 | 6 | uniform mat4 osg_ViewMatrixInverse; 7 | uniform mat4 osg_ViewMatrix; 8 | 9 | varying vec4 vWorldVertex; 10 | 11 | void main(void) 12 | { 13 | // Transform the vertex into world space 14 | vWorldVertex = (osg_ViewMatrixInverse * gl_ModelViewMatrix) * gl_Vertex; 15 | vWorldVertex.xyzw /= vWorldVertex.w; 16 | 17 | // Project the vertex onto the ocean plane 18 | vec4 projectedVertex = vWorldVertex; 19 | projectedVertex.z = osgOcean_WaterHeight; 20 | 21 | gl_Position = (gl_ProjectionMatrix * osg_ViewMatrix) * projectedVertex; 22 | 23 | return; 24 | } 25 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_ocean_scene.frag: -------------------------------------------------------------------------------- 1 | // osgOcean Uniforms 2 | // ----------------- 3 | uniform float osgOcean_DOF_Near; 4 | uniform float osgOcean_DOF_Focus; 5 | uniform float osgOcean_DOF_Far; 6 | uniform float osgOcean_DOF_Clamp; 7 | 8 | uniform float osgOcean_UnderwaterFogDensity; 9 | uniform float osgOcean_AboveWaterFogDensity; 10 | uniform vec4 osgOcean_UnderwaterFogColor; 11 | uniform vec4 osgOcean_AboveWaterFogColor; 12 | 13 | uniform float osgOcean_WaterHeight; 14 | 15 | uniform bool osgOcean_EnableGlare; 16 | uniform bool osgOcean_EnableDOF; 17 | uniform bool osgOcean_EyeUnderwater; 18 | uniform bool osgOcean_EnableUnderwaterScattering; 19 | // ------------------- 20 | 21 | uniform sampler2D uTextureMap; 22 | 23 | varying vec3 vExtinction; 24 | varying vec3 vInScattering; 25 | varying vec3 vNormal; 26 | varying vec3 vLightDir; 27 | varying vec3 vEyeVec; 28 | 29 | varying float vWorldHeight; 30 | 31 | float computeDepthBlur(float depth, float focus, float near, float far, float clampval ) 32 | { 33 | float f; 34 | if (depth < focus){ 35 | f = (depth - focus)/(focus - near); 36 | } 37 | else{ 38 | f = (depth - focus)/(far - focus); 39 | f = clamp(f, 0.0, clampval); 40 | } 41 | return f * 0.5 + 0.5; 42 | } 43 | 44 | vec4 lighting( vec4 colormap ) 45 | { 46 | vec4 final_color = gl_LightSource[osgOcean_LightID].ambient * colormap; 47 | 48 | vec3 N = normalize(vNormal); 49 | vec3 L = normalize(vLightDir); 50 | 51 | float lambertTerm = dot(N,L); 52 | 53 | if(lambertTerm > 0.0) 54 | { 55 | final_color += gl_LightSource[osgOcean_LightID].diffuse * lambertTerm * colormap; 56 | 57 | vec3 E = normalize(vEyeVec); 58 | vec3 R = reflect(-L, N); 59 | 60 | float specular = pow( max(dot(R, E), 0.0), 2.0 ); 61 | 62 | final_color += gl_LightSource[osgOcean_LightID].specular * specular; 63 | } 64 | 65 | return final_color; 66 | } 67 | 68 | float computeFogFactor( float density, float fogCoord ) 69 | { 70 | return exp2(density * fogCoord * fogCoord ); 71 | } 72 | 73 | void main(void) 74 | { 75 | vec4 final_color; 76 | 77 | vec4 textureColor = texture2D( uTextureMap, gl_TexCoord[0].st ); 78 | 79 | // Underwater 80 | // +2 tweak here as waves peak above average wave height, 81 | // and surface fog becomes visible. 82 | if(osgOcean_EyeUnderwater && vWorldHeight < osgOcean_WaterHeight+2.0 ) 83 | { 84 | final_color = lighting( textureColor ); 85 | 86 | // mix in underwater light 87 | if(osgOcean_EnableUnderwaterScattering) 88 | { 89 | final_color.rgb = final_color.rgb * vExtinction + vInScattering; 90 | } 91 | 92 | float fogFactor = computeFogFactor( osgOcean_UnderwaterFogDensity, gl_FogFragCoord ); 93 | 94 | // write to depth buffer (actually a GL_LUMINANCE) 95 | if(osgOcean_EnableDOF) 96 | { 97 | float depth = computeDepthBlur(gl_FogFragCoord, osgOcean_DOF_Focus, osgOcean_DOF_Near, osgOcean_DOF_Far, osgOcean_DOF_Clamp); 98 | gl_FragData[1] = vec4(depth); 99 | } 100 | 101 | // color buffer 102 | gl_FragData[0] = mix( osgOcean_UnderwaterFogColor, final_color, fogFactor ); 103 | } 104 | // Above water 105 | else 106 | { 107 | final_color = lighting( textureColor ); 108 | 109 | float fogFactor = computeFogFactor( osgOcean_AboveWaterFogDensity, gl_FogFragCoord ); 110 | final_color = mix( osgOcean_AboveWaterFogColor, final_color, fogFactor ); 111 | 112 | // write to luminance buffer 113 | // might not need the IF here, glsl compiler doesn't complain if 114 | // you try and write to a FragData index that doesn't exist. But since 115 | // Mac GLSL support seems so fussy I'll leave it in. 116 | if(osgOcean_EnableGlare) 117 | { 118 | gl_FragData[1] = vec4(0.0); 119 | } 120 | 121 | // write to color buffer 122 | gl_FragData[0] = final_color; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_ocean_scene.vert: -------------------------------------------------------------------------------- 1 | // osgOcean Uniforms 2 | // ----------------- 3 | uniform mat4 osg_ViewMatrixInverse; 4 | uniform float osgOcean_WaterHeight; 5 | uniform vec3 osgOcean_Eye; 6 | uniform vec3 osgOcean_UnderwaterAttenuation; 7 | uniform vec4 osgOcean_UnderwaterDiffuse; 8 | uniform bool osgOcean_EnableUnderwaterScattering; 9 | // ----------------- 10 | 11 | varying vec3 vExtinction; 12 | varying vec3 vInScattering; 13 | 14 | varying vec3 vNormal; 15 | varying vec3 vLightDir; 16 | varying vec3 vEyeVec; 17 | varying float vWorldHeight; 18 | 19 | void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering ) 20 | { 21 | float viewDist = length(eye-worldVertex); 22 | 23 | float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0); 24 | 25 | extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0); 26 | 27 | // Need to compute accurate kd constant. 28 | // const vec3 kd = vec3(0.001, 0.001, 0.001); 29 | inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001))); 30 | } 31 | 32 | void main(void) 33 | { 34 | gl_TexCoord[0] = gl_MultiTexCoord0; 35 | gl_Position = ftransform(); 36 | gl_FogFragCoord = gl_Position.z; 37 | gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; // for reflections 38 | 39 | vNormal = gl_NormalMatrix * gl_Normal; 40 | vLightDir = gl_LightSource[osgOcean_LightID].position.xyz; 41 | vEyeVec = -vec3(gl_ModelViewMatrix*gl_Vertex); 42 | 43 | vec4 worldVertex = (osg_ViewMatrixInverse*gl_ModelViewMatrix) * gl_Vertex; 44 | 45 | if (osgOcean_EnableUnderwaterScattering) 46 | computeScattering( osgOcean_Eye, worldVertex.xyz, vExtinction, vInScattering); 47 | 48 | vWorldHeight = worldVertex.z; 49 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_ocean_scene_lispsm.frag: -------------------------------------------------------------------------------- 1 | // osgOcean Uniforms 2 | // ----------------- 3 | uniform float osgOcean_DOF_Near; 4 | uniform float osgOcean_DOF_Focus; 5 | uniform float osgOcean_DOF_Far; 6 | uniform float osgOcean_DOF_Clamp; 7 | 8 | uniform float osgOcean_UnderwaterFogDensity; 9 | uniform float osgOcean_AboveWaterFogDensity; 10 | uniform vec4 osgOcean_UnderwaterFogColor; 11 | uniform vec4 osgOcean_AboveWaterFogColor; 12 | 13 | uniform float osgOcean_WaterHeight; 14 | 15 | uniform bool osgOcean_EnableGlare; 16 | uniform bool osgOcean_EnableDOF; 17 | uniform bool osgOcean_EyeUnderwater; 18 | uniform bool osgOcean_EnableUnderwaterScattering; 19 | // ------------------- 20 | 21 | uniform sampler2D uTextureMap; 22 | 23 | varying vec3 vExtinction; 24 | varying vec3 vInScattering; 25 | varying vec3 vNormal; 26 | varying vec3 vLightDir; 27 | varying vec3 vEyeVec; 28 | 29 | varying float vWorldHeight; 30 | 31 | uniform sampler2DShadow shadowTexture; 32 | 33 | float computeDepthBlur(float depth, float focus, float near, float far, float clampval ) 34 | { 35 | float f; 36 | if (depth < focus){ 37 | f = (depth - focus)/(focus - near); 38 | } 39 | else{ 40 | f = (depth - focus)/(far - focus); 41 | f = clamp(f, 0.0, clampval); 42 | } 43 | return f * 0.5 + 0.5; 44 | } 45 | 46 | vec4 lighting( vec4 colormap ) 47 | { 48 | vec4 final_color = gl_LightSource[0].ambient * colormap; 49 | 50 | float light = shadow2DProj( shadowTexture, gl_TexCoord[7] ).r; 51 | 52 | vec3 N = normalize(vNormal); 53 | vec3 L = normalize(vLightDir); 54 | 55 | float lambertTerm = dot(N,L); 56 | 57 | if(lambertTerm > 0.0) 58 | { 59 | final_color += gl_LightSource[0].diffuse * lambertTerm * colormap * light; 60 | 61 | vec3 E = normalize(vEyeVec); 62 | vec3 R = reflect(-L, N); 63 | 64 | float specular = pow( max(dot(R, E), 0.0), 2.0 ); 65 | 66 | final_color += gl_LightSource[0].specular * specular * light; 67 | } 68 | 69 | return final_color; 70 | } 71 | 72 | float computeFogFactor( float density, float fogCoord ) 73 | { 74 | return exp2(density * fogCoord * fogCoord ); 75 | } 76 | 77 | void main(void) 78 | { 79 | vec4 final_color; 80 | 81 | vec4 textureColor = texture2D( uTextureMap, gl_TexCoord[0].st ); 82 | 83 | // Underwater 84 | // +2 tweak here as waves peak above average wave height, 85 | // and surface fog becomes visible. 86 | if(osgOcean_EyeUnderwater && vWorldHeight < osgOcean_WaterHeight+2.0 ) 87 | { 88 | final_color = lighting( textureColor ); 89 | 90 | // mix in underwater light 91 | if(osgOcean_EnableUnderwaterScattering) 92 | { 93 | final_color.rgb = final_color.rgb * vExtinction + vInScattering; 94 | } 95 | 96 | float fogFactor = computeFogFactor( osgOcean_UnderwaterFogDensity, gl_FogFragCoord ); 97 | 98 | // write to depth buffer (actually a GL_LUMINANCE) 99 | if(osgOcean_EnableDOF) 100 | { 101 | float depth = computeDepthBlur(gl_FogFragCoord, osgOcean_DOF_Focus, osgOcean_DOF_Near, osgOcean_DOF_Far, osgOcean_DOF_Clamp); 102 | gl_FragData[1] = vec4(depth); 103 | } 104 | 105 | // color buffer 106 | gl_FragData[0] = mix( osgOcean_UnderwaterFogColor, final_color, fogFactor ); 107 | } 108 | // Above water 109 | else 110 | { 111 | final_color = lighting( textureColor ); 112 | 113 | float fogFactor = computeFogFactor( osgOcean_AboveWaterFogDensity, gl_FogFragCoord ); 114 | final_color = mix( osgOcean_AboveWaterFogColor, final_color, fogFactor ); 115 | 116 | // write to luminance buffer 117 | // might not need the IF here, glsl compiler doesn't complain if 118 | // you try and write to a FragData index that doesn't exist. But since 119 | // Mac GLSL support seems so fussy I'll leave it in. 120 | if(osgOcean_EnableGlare) 121 | { 122 | gl_FragData[1] = vec4(0.0); 123 | } 124 | 125 | // write to color buffer 126 | gl_FragData[0] = final_color; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /resources/shaders/osgOcean_ocean_scene_lispsm.vert: -------------------------------------------------------------------------------- 1 | // osgOcean Uniforms 2 | // ----------------- 3 | uniform mat4 osg_ViewMatrixInverse; 4 | uniform float osgOcean_WaterHeight; 5 | uniform vec3 osgOcean_Eye; 6 | uniform vec3 osgOcean_UnderwaterAttenuation; 7 | uniform vec4 osgOcean_UnderwaterDiffuse; 8 | uniform bool osgOcean_EnableUnderwaterScattering; 9 | // ----------------- 10 | 11 | varying vec3 vExtinction; 12 | varying vec3 vInScattering; 13 | 14 | varying vec3 vNormal; 15 | varying vec3 vLightDir; 16 | varying vec3 vEyeVec; 17 | varying float vWorldHeight; 18 | 19 | void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering ) 20 | { 21 | float viewDist = length(eye-worldVertex); 22 | 23 | float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0); 24 | 25 | extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0); 26 | 27 | // Need to compute accurate kd constant. 28 | // const vec3 kd = vec3(0.001, 0.001, 0.001); 29 | inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001))); 30 | } 31 | 32 | void main(void) 33 | { 34 | gl_TexCoord[0] = gl_MultiTexCoord0; 35 | gl_Position = ftransform(); 36 | gl_FogFragCoord = gl_Position.z; 37 | vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; 38 | gl_ClipVertex = ecPosition; // for reflections 39 | 40 | vNormal = gl_NormalMatrix * gl_Normal; 41 | vLightDir = gl_LightSource[0].position.xyz; 42 | vEyeVec = -vec3(gl_ModelViewMatrix*gl_Vertex); 43 | 44 | vec4 worldVertex = (osg_ViewMatrixInverse*gl_ModelViewMatrix) * gl_Vertex; 45 | 46 | if (osgOcean_EnableUnderwaterScattering) 47 | computeScattering( osgOcean_Eye, worldVertex.xyz, vExtinction, vInScattering); 48 | 49 | vWorldHeight = worldVertex.z; 50 | 51 | // Generate shadow map coords 52 | gl_TexCoord[7].s = dot( ecPosition, gl_EyePlaneS[7] ); 53 | gl_TexCoord[7].t = dot( ecPosition, gl_EyePlaneT[7] ); 54 | gl_TexCoord[7].p = dot( ecPosition, gl_EyePlaneR[7] ); 55 | gl_TexCoord[7].q = dot( ecPosition, gl_EyePlaneQ[7] ); 56 | 57 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_ocean_surface.vert: -------------------------------------------------------------------------------- 1 | uniform mat4 osg_ViewMatrixInverse; 2 | 3 | uniform vec3 osgOcean_Eye; 4 | 5 | uniform vec3 osgOcean_NoiseCoords0; 6 | uniform vec3 osgOcean_NoiseCoords1; 7 | 8 | uniform vec4 osgOcean_WaveTop; 9 | uniform vec4 osgOcean_WaveBot; 10 | 11 | uniform float osgOcean_FoamScale; 12 | 13 | uniform float osgOcean_FrameTime; 14 | 15 | // Used to blend the waves into a sinus curve near the shore 16 | uniform sampler2D osgOcean_Heightmap; 17 | uniform bool osgOcean_EnableHeightmap; 18 | 19 | uniform bool osgOcean_EnableUnderwaterScattering; 20 | uniform float osgOcean_WaterHeight; 21 | uniform vec3 osgOcean_UnderwaterAttenuation; 22 | uniform vec4 osgOcean_UnderwaterDiffuse; 23 | 24 | varying vec4 vVertex; 25 | varying vec4 vWorldVertex; 26 | varying vec3 vNormal; 27 | varying vec3 vViewerDir; 28 | varying vec3 vLightDir; 29 | 30 | varying vec3 vExtinction; 31 | varying vec3 vInScattering; 32 | 33 | varying vec3 vWorldViewDir; 34 | varying vec3 vWorldNormal; 35 | 36 | varying float height; 37 | 38 | mat3 get3x3Matrix( mat4 m ) 39 | { 40 | mat3 result; 41 | 42 | result[0][0] = m[0][0]; 43 | result[0][1] = m[0][1]; 44 | result[0][2] = m[0][2]; 45 | 46 | result[1][0] = m[1][0]; 47 | result[1][1] = m[1][1]; 48 | result[1][2] = m[1][2]; 49 | 50 | result[2][0] = m[2][0]; 51 | result[2][1] = m[2][1]; 52 | result[2][2] = m[2][2]; 53 | 54 | return result; 55 | } 56 | 57 | void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering ) 58 | { 59 | float viewDist = length(eye-worldVertex); 60 | 61 | float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0); 62 | 63 | extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0); 64 | 65 | // Need to compute accurate kd constant. 66 | // const vec3 kd = vec3(0.001, 0.001, 0.001); 67 | inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001))); 68 | } 69 | 70 | // ------------------------------- 71 | // Main Program 72 | // ------------------------------- 73 | 74 | void main( void ) 75 | { 76 | // Transform the vertex 77 | vec4 inputVertex = gl_Vertex; 78 | gl_Position = gl_ModelViewProjectionMatrix * inputVertex; 79 | 80 | // Blend the wave into a sinus curve near the shore 81 | // note that this requires a vertex shader texture lookup 82 | // vertex has to be transformed a second time with the new z-value 83 | if (osgOcean_EnableHeightmap) 84 | { 85 | vec2 screenCoords = gl_Position.xy / gl_Position.w; 86 | 87 | height = pow(clamp(1.0 - texture2D(osgOcean_Heightmap, clamp(screenCoords * 0.5 + 0.5, 0.0, 1.0)).x, 0.0, 1.0), 32.0); 88 | 89 | inputVertex = vec4(gl_Vertex.x, 90 | gl_Vertex.y, 91 | mix(gl_Vertex.z, sin(osgOcean_FrameTime), height), 92 | gl_Vertex.w); 93 | 94 | gl_Position = gl_ModelViewProjectionMatrix * inputVertex; 95 | } 96 | 97 | // ----------------------------------------------------------- 98 | 99 | // In object space 100 | vVertex = inputVertex; 101 | vLightDir = normalize( vec3( gl_ModelViewMatrixInverse * ( gl_LightSource[osgOcean_LightID].position ) ) ); 102 | vViewerDir = gl_ModelViewMatrixInverse[3].xyz - inputVertex.xyz; 103 | vNormal = normalize(gl_Normal); 104 | 105 | vec4 waveColorDiff = osgOcean_WaveTop - osgOcean_WaveBot; 106 | 107 | gl_FrontColor = waveColorDiff * 108 | clamp((gl_Vertex.z + osgOcean_Eye.z) * 0.1111111 + vNormal.z - 0.4666667, 0.0, 1.0) + osgOcean_WaveBot; 109 | 110 | // ------------------------------------------------------------- 111 | 112 | mat4 modelMatrix = osg_ViewMatrixInverse * gl_ModelViewMatrix; 113 | mat3 modelMatrix3x3 = get3x3Matrix( modelMatrix ); 114 | 115 | // world space 116 | vWorldVertex = modelMatrix * gl_Vertex; 117 | vWorldNormal = modelMatrix3x3 * gl_Normal; 118 | vWorldViewDir = vWorldVertex.xyz - osgOcean_Eye.xyz; 119 | 120 | // ------------- Texture Coords --------------------------------- 121 | 122 | // Normal Map Coords 123 | gl_TexCoord[0].xy = ( gl_Vertex.xy * osgOcean_NoiseCoords0.z + osgOcean_NoiseCoords0.xy ); 124 | gl_TexCoord[0].zw = ( gl_Vertex.xy * osgOcean_NoiseCoords1.z + osgOcean_NoiseCoords1.xy ); 125 | gl_TexCoord[0].y = -gl_TexCoord[0].y; 126 | gl_TexCoord[0].w = -gl_TexCoord[0].w; 127 | 128 | // Foam coords 129 | gl_TexCoord[1].st = gl_Vertex.xy * osgOcean_FoamScale; 130 | 131 | // Fog coords 132 | gl_FogFragCoord = gl_Position.z; 133 | 134 | if (osgOcean_EnableUnderwaterScattering) 135 | computeScattering( osgOcean_Eye, vWorldVertex.xyz, vExtinction, vInScattering); 136 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_ocean_surface_vbo.vert: -------------------------------------------------------------------------------- 1 | uniform mat4 osg_ViewMatrixInverse; 2 | uniform float osg_FrameTime; 3 | 4 | uniform vec3 osgOcean_Eye; 5 | 6 | uniform vec3 osgOcean_NoiseCoords0; 7 | uniform vec3 osgOcean_NoiseCoords1; 8 | 9 | uniform vec4 osgOcean_WaveTop; 10 | uniform vec4 osgOcean_WaveBot; 11 | 12 | uniform float osgOcean_FoamScale; 13 | 14 | // Used to blend the waves into a sinus curve near the shore 15 | uniform sampler2D osgOcean_Heightmap; 16 | uniform bool osgOcean_EnableHeightmap; 17 | 18 | uniform bool osgOcean_EnableUnderwaterScattering; 19 | uniform float osgOcean_WaterHeight; 20 | uniform vec3 osgOcean_UnderwaterAttenuation; 21 | uniform vec4 osgOcean_UnderwaterDiffuse; 22 | 23 | varying vec4 vVertex; 24 | varying vec4 vWorldVertex; 25 | varying vec3 vNormal; 26 | varying vec3 vViewerDir; 27 | varying vec3 vLightDir; 28 | 29 | varying vec3 vExtinction; 30 | varying vec3 vInScattering; 31 | 32 | varying vec3 vWorldViewDir; 33 | varying vec3 vWorldNormal; 34 | 35 | varying float height; 36 | 37 | mat3 get3x3Matrix( mat4 m ) 38 | { 39 | mat3 result; 40 | 41 | result[0][0] = m[0][0]; 42 | result[0][1] = m[0][1]; 43 | result[0][2] = m[0][2]; 44 | 45 | result[1][0] = m[1][0]; 46 | result[1][1] = m[1][1]; 47 | result[1][2] = m[1][2]; 48 | 49 | result[2][0] = m[2][0]; 50 | result[2][1] = m[2][1]; 51 | result[2][2] = m[2][2]; 52 | 53 | return result; 54 | } 55 | 56 | void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering ) 57 | { 58 | float viewDist = length(eye-worldVertex); 59 | 60 | float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0); 61 | 62 | extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0); 63 | 64 | // Need to compute accurate kd constant. 65 | // const vec3 kd = vec3(0.001, 0.001, 0.001); 66 | inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001))); 67 | } 68 | 69 | // ------------------------------- 70 | // Main Program 71 | // ------------------------------- 72 | 73 | void main( void ) 74 | { 75 | // Transform the vertex 76 | vec4 inputVertex = gl_Vertex; 77 | inputVertex.xyz += gl_Color.xyz; 78 | 79 | gl_Position = gl_ModelViewProjectionMatrix * inputVertex; 80 | 81 | // Blend the wave into a sinus curve near the shore 82 | // note that this requires a vertex shader texture lookup 83 | // vertex has to be transformed a second time with the new z-value 84 | if (osgOcean_EnableHeightmap) 85 | { 86 | vec2 screenCoords = gl_Position.xy / gl_Position.w; 87 | 88 | height = pow(clamp(1.0 - texture2D(osgOcean_Heightmap, clamp(screenCoords * 0.5 + 0.5, 0.0, 1.0)).x, 0.0, 1.0), 32.0); 89 | 90 | inputVertex = vec4(inputVertex.x, 91 | inputVertex.y, 92 | mix(inputVertex.z, sin(osg_FrameTime), height), 93 | inputVertex.w); 94 | 95 | gl_Position = gl_ModelViewProjectionMatrix * inputVertex; 96 | } 97 | 98 | // ----------------------------------------------------------- 99 | 100 | // In object space 101 | vVertex = inputVertex; 102 | vLightDir = normalize( vec3( gl_ModelViewMatrixInverse * ( gl_LightSource[osgOcean_LightID].position ) ) ); 103 | vViewerDir = gl_ModelViewMatrixInverse[3].xyz - inputVertex.xyz; 104 | vNormal = normalize(gl_Normal); 105 | 106 | vec4 waveColorDiff = osgOcean_WaveTop-osgOcean_WaveBot; 107 | 108 | gl_FrontColor = waveColorDiff * 109 | clamp((inputVertex.z + osgOcean_Eye.z) * 0.1111111 + vNormal.z - 0.4666667, 0.0, 1.0) + osgOcean_WaveBot; 110 | 111 | // ------------------------------------------------------------- 112 | 113 | mat4 modelMatrix = osg_ViewMatrixInverse * gl_ModelViewMatrix; 114 | mat3 modelMatrix3x3 = get3x3Matrix( modelMatrix ); 115 | 116 | // world space 117 | vWorldVertex = modelMatrix * inputVertex; 118 | vWorldNormal = modelMatrix3x3 * gl_Normal; 119 | vWorldViewDir = vWorldVertex.xyz - osgOcean_Eye.xyz; 120 | 121 | // ------------- Texture Coords --------------------------------- 122 | 123 | // Normal Map Coords 124 | gl_TexCoord[0].xy = ( inputVertex.xy * osgOcean_NoiseCoords0.z + osgOcean_NoiseCoords0.xy ); 125 | gl_TexCoord[0].zw = ( inputVertex.xy * osgOcean_NoiseCoords1.z + osgOcean_NoiseCoords1.xy ); 126 | gl_TexCoord[0].y = -gl_TexCoord[0].y; 127 | gl_TexCoord[0].w = -gl_TexCoord[0].w; 128 | 129 | // Foam coords 130 | gl_TexCoord[1].st = inputVertex.xy * osgOcean_FoamScale; 131 | 132 | // Fog coords 133 | gl_FogFragCoord = gl_Position.z; 134 | 135 | if (osgOcean_EnableUnderwaterScattering) 136 | computeScattering( osgOcean_Eye, vWorldVertex.xyz, vExtinction, vInScattering); 137 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_silt_points.frag: -------------------------------------------------------------------------------- 1 | uniform sampler2D osgOcean_BaseTexture; 2 | varying vec4 colour; 3 | 4 | void main (void) 5 | { 6 | gl_FragColor = colour * texture2D( osgOcean_BaseTexture, gl_TexCoord[0].xy); 7 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_silt_points.vert: -------------------------------------------------------------------------------- 1 | uniform float osgOcean_InversePeriod; 2 | uniform vec4 osgOcean_ParticleColour; 3 | uniform float osgOcean_ParticleSize; 4 | 5 | uniform float osg_SimulationTime; 6 | 7 | varying vec4 colour; 8 | 9 | void main(void) 10 | { 11 | float startTime = gl_MultiTexCoord1.x; 12 | 13 | vec4 v_current = gl_Vertex; 14 | 15 | float disp = (osg_SimulationTime - startTime)*osgOcean_InversePeriod; 16 | 17 | vec3 direction = sign(gl_Normal); 18 | 19 | v_current.x = direction.x * fract( disp + gl_Vertex.x ); 20 | v_current.y = direction.y * fract( disp + gl_Vertex.y ); 21 | v_current.z = direction.z * fract( disp + gl_Vertex.z ); 22 | 23 | colour = osgOcean_ParticleColour; 24 | 25 | gl_Position = gl_ModelViewProjectionMatrix * v_current; 26 | 27 | float pointSize = abs(1280.0*osgOcean_ParticleSize / gl_Position.w); 28 | 29 | gl_PointSize = ceil(pointSize); 30 | 31 | colour.a = 0.05+(pointSize*pointSize)/(gl_PointSize*gl_PointSize); 32 | 33 | gl_ClipVertex = v_current; 34 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_silt_quads.frag: -------------------------------------------------------------------------------- 1 | uniform sampler2D osgOcean_BaseTexture; 2 | varying vec2 texCoord; 3 | varying vec4 colour; 4 | 5 | void main (void) 6 | { 7 | gl_FragColor = colour * texture2D( osgOcean_BaseTexture, texCoord); 8 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_silt_quads.vert: -------------------------------------------------------------------------------- 1 | uniform vec4 osgOcean_ParticleColour; 2 | 3 | uniform float osgOcean_InversePeriod; 4 | uniform float osgOcean_ParticleSize; 5 | uniform float osg_SimulationTime; 6 | uniform float osg_DeltaSimulationTime; 7 | 8 | varying vec4 colour; 9 | varying vec2 texCoord; 10 | 11 | void main(void) 12 | { 13 | float startTime = gl_MultiTexCoord1.x; 14 | texCoord = gl_MultiTexCoord0.xy; 15 | 16 | float disp = (osg_SimulationTime - startTime)*osgOcean_InversePeriod; 17 | 18 | vec4 v_previous = gl_Vertex; 19 | 20 | vec3 direction = sign(gl_Normal); 21 | 22 | v_previous.x = direction.x * fract( disp + gl_Vertex.x ); 23 | v_previous.y = direction.y * fract( disp + gl_Vertex.y ); 24 | v_previous.z = direction.z * fract( disp + gl_Vertex.z ); 25 | 26 | vec4 v_current = v_previous; 27 | 28 | v_current.x += ( osg_DeltaSimulationTime * osgOcean_InversePeriod ); 29 | v_current.y += ( osg_DeltaSimulationTime * osgOcean_InversePeriod ); 30 | v_current.z += ( osg_DeltaSimulationTime * osgOcean_InversePeriod ); 31 | 32 | colour = osgOcean_ParticleColour; 33 | 34 | vec4 v1 = gl_ModelViewMatrix * v_current; 35 | vec4 v2 = gl_ModelViewMatrix * v_previous; 36 | 37 | vec3 dv = v2.xyz - v1.xyz; 38 | 39 | vec2 dv_normalized = normalize(dv.xy); 40 | dv.xy += dv_normalized * osgOcean_ParticleSize; 41 | vec2 dp = vec2( -dv_normalized.y, dv_normalized.x ) * osgOcean_ParticleSize; 42 | 43 | float area = length(dv.xy); 44 | colour.a = 0.05+(osgOcean_ParticleSize)/area; 45 | 46 | v1.xyz += dv*texCoord.y; 47 | v1.xy += dp*texCoord.x; 48 | 49 | gl_Position = gl_ProjectionMatrix * v1; 50 | gl_Position.z = 0.01; 51 | gl_ClipVertex = v1; 52 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_streak.frag: -------------------------------------------------------------------------------- 1 | #extension GL_ARB_texture_rectangle : enable 2 | 3 | #define NUM_SAMPLES 4 4 | 5 | uniform sampler2DRect osgOcean_Buffer; 6 | uniform vec2 osgOcean_Direction; 7 | uniform float osgOcean_Attenuation; 8 | uniform float osgOcean_Pass; 9 | 10 | void main(void) 11 | { 12 | vec2 sampleCoord = vec2(0.0); 13 | vec3 cOut = vec3(0.0); 14 | 15 | // sample weight = a^(b*s) 16 | // a = attenuation 17 | // b = 4^(pass-1) 18 | // s = sample number 19 | 20 | vec2 pxSize = vec2(0.5); 21 | 22 | float b = pow( float(NUM_SAMPLES), float(osgOcean_Pass)); 23 | float sf = 0.0; 24 | 25 | for (int s = 0; s < NUM_SAMPLES; s++) 26 | { 27 | sf = float(s); 28 | float weight = pow(osgOcean_Attenuation, b * sf); 29 | sampleCoord = gl_TexCoord[0].st + (osgOcean_Direction * b * vec2(sf) * pxSize); 30 | cOut += clamp(weight,0.0,1.0) * texture2DRect(osgOcean_Buffer, sampleCoord).rgb; 31 | } 32 | 33 | vec3 streak = clamp(cOut, 0.0, 1.0); 34 | 35 | gl_FragColor = vec4(streak,1.0); 36 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_streak.vert: -------------------------------------------------------------------------------- 1 | 2 | void main(void) 3 | { 4 | gl_TexCoord[0] = gl_MultiTexCoord0; 5 | gl_Position = ftransform(); 6 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_water_distortion.frag: -------------------------------------------------------------------------------- 1 | // Based on Jon Kennedy's heat haze shader 2 | // Copyright (c) 2002-2006 3Dlabs Inc. Ltd. 3 | 4 | uniform float osgOcean_Frequency; 5 | uniform float osgOcean_Offset; 6 | uniform float osgOcean_Speed; 7 | uniform vec2 osgOcean_ScreenRes; 8 | 9 | uniform sampler2DRect osgOcean_FrameBuffer; 10 | 11 | varying vec4 vEyePos; 12 | 13 | void main (void) 14 | { 15 | vec2 index; 16 | 17 | // perform the div by w to put the texture into screen space 18 | float recipW = 1.0 / vEyePos.w; 19 | vec2 eye = vEyePos.xy * vec2(recipW); 20 | 21 | float blend = max(1.0 - eye.y, 0.0); 22 | 23 | // calc the wobble 24 | // index.s = eye.x ; 25 | index.s = eye.x + blend * sin( osgOcean_Frequency * 5.0 * eye.x + osgOcean_Offset * osgOcean_Speed ) * 0.004; 26 | index.t = eye.y + blend * sin( osgOcean_Frequency * 5.0 * eye.y + osgOcean_Offset * osgOcean_Speed ) * 0.004; 27 | 28 | // scale and shift so we're in the range 0-1 29 | index.s = index.s * 0.5 + 0.5; 30 | index.t = index.t * 0.5 + 0.5; 31 | 32 | vec2 recipRes = vec2(1.0/osgOcean_ScreenRes.x, 1.0/osgOcean_ScreenRes.y); 33 | 34 | index.s = clamp(index.s, 0.0, 1.0 - recipRes.x); 35 | index.t = clamp(index.t, 0.0, 1.0 - recipRes.y); 36 | 37 | // scale the texture so we just see the rendered framebuffer 38 | index.s = index.s * osgOcean_ScreenRes.x; 39 | index.t = index.t * osgOcean_ScreenRes.y; 40 | 41 | vec3 RefractionColor = vec3( texture2DRect( osgOcean_FrameBuffer, index ) ); 42 | 43 | gl_FragColor = vec4( RefractionColor, 1.0 ); 44 | //gl_FragColor = texture2DRect( osgOcean_FrameBuffer, gl_TexCoord[0].st ); 45 | } -------------------------------------------------------------------------------- /resources/shaders/osgOcean_water_distortion.vert: -------------------------------------------------------------------------------- 1 | varying vec4 vEyePos; 2 | 3 | void main(void) 4 | { 5 | gl_TexCoord[0] = gl_MultiTexCoord0; 6 | vEyePos = gl_ModelViewProjectionMatrix * gl_Vertex; 7 | gl_Position = ftransform(); 8 | } -------------------------------------------------------------------------------- /resources/shaders/skydome.frag: -------------------------------------------------------------------------------- 1 | uniform samplerCube uEnvironmentMap; 2 | 3 | varying vec3 vTexCoord; 4 | 5 | void main(void) 6 | { 7 | vec3 texcoord = vec3(vTexCoord.x, vTexCoord.y, -vTexCoord.z); 8 | gl_FragData[0] = textureCube( uEnvironmentMap, texcoord.xzy ); 9 | gl_FragData[0].a = 0.0; 10 | gl_FragData[1] = vec4(0.0); 11 | } -------------------------------------------------------------------------------- /resources/shaders/skydome.vert: -------------------------------------------------------------------------------- 1 | varying vec3 vTexCoord; 2 | 3 | void main(void) 4 | { 5 | gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0); 6 | 7 | vTexCoord = gl_Vertex.xyz; 8 | } -------------------------------------------------------------------------------- /resources/shaders/terrain.frag: -------------------------------------------------------------------------------- 1 | // osgOcean uniforms 2 | // ------------------- 3 | uniform float osgOcean_DOF_Near; 4 | uniform float osgOcean_DOF_Focus; 5 | uniform float osgOcean_DOF_Far; 6 | uniform float osgOcean_DOF_Clamp; 7 | 8 | uniform bool osgOcean_EnableGlare; 9 | uniform bool osgOcean_EnableDOF; 10 | uniform bool osgOcean_EyeUnderwater; 11 | uniform bool osgOcean_EnableUnderwaterScattering; 12 | 13 | uniform float osgOcean_UnderwaterFogDensity; 14 | uniform float osgOcean_AboveWaterFogDensity; 15 | uniform float osgOcean_WaterHeight; 16 | 17 | uniform vec4 osgOcean_UnderwaterFogColor; 18 | uniform vec4 osgOcean_AboveWaterFogColor; 19 | // ------------------- 20 | 21 | uniform sampler2D uTextureMap; 22 | uniform sampler2D uOverlayMap; 23 | uniform sampler2D uNormalMap; 24 | 25 | varying vec3 vLightDir; 26 | varying vec3 vEyeVec; 27 | varying vec3 vExtinction; 28 | varying vec3 vInScattering; 29 | 30 | varying vec4 vWorldVertex; 31 | 32 | varying float vUnitHeight; 33 | 34 | float computeDepthBlur(float depth, float focus, float near, float far, float clampval ) 35 | { 36 | float f; 37 | if (depth < focus){ 38 | f = (depth - focus)/(focus - near); 39 | } 40 | else{ 41 | f = (depth - focus)/(far - focus); 42 | f = clamp(f, 0.0, clampval); 43 | } 44 | return f * 0.5 + 0.5; 45 | } 46 | 47 | vec4 lighting( in vec4 colormap, in vec3 N ) 48 | { 49 | vec4 final_color = gl_LightSource[osgOcean_LightID].ambient * colormap; 50 | 51 | vec3 L = normalize(vLightDir); 52 | 53 | float lambertTerm = dot(N,L); 54 | 55 | if(lambertTerm > 0.0) 56 | { 57 | final_color += gl_LightSource[osgOcean_LightID].diffuse * lambertTerm * colormap; 58 | 59 | vec3 E = normalize(vEyeVec); 60 | vec3 R = reflect(-L, N); 61 | 62 | float specular = pow( max(dot(R, E), 0.0), 2.0 ); 63 | 64 | final_color += gl_LightSource[osgOcean_LightID].specular * specular; 65 | } 66 | 67 | return final_color; 68 | } 69 | 70 | float computeFogFactor( float density, float fogCoord ) 71 | { 72 | return exp2(density * fogCoord * fogCoord ); 73 | } 74 | 75 | void main(void) 76 | { 77 | vec4 baseColor = texture2D( uTextureMap, gl_TexCoord[0].st ); 78 | vec4 overlayColor = texture2D( uOverlayMap, gl_TexCoord[1].st ); 79 | vec4 bumpColor = texture2D( uNormalMap, gl_TexCoord[0].st ); 80 | 81 | float unitHeight = clamp( vUnitHeight, 0.0, 1.0); 82 | vec4 textureColor = mix(overlayColor, baseColor, unitHeight); 83 | 84 | vec3 bump = (bumpColor.xyz*2.0)-1.0; 85 | 86 | float fogFactor = 0.0; 87 | vec4 fogColor; 88 | 89 | vec4 final_color = lighting( textureColor, bump ); 90 | 91 | // +2 tweak here as waves peak above average wave height, 92 | // and surface fog becomes visible. 93 | if(osgOcean_EyeUnderwater && vWorldVertex.z < osgOcean_WaterHeight+2.0) 94 | { 95 | // mix in underwater light 96 | if( osgOcean_EnableUnderwaterScattering ) 97 | { 98 | final_color.rgb = final_color.rgb * vExtinction + vInScattering; 99 | } 100 | 101 | fogFactor = computeFogFactor( osgOcean_UnderwaterFogDensity, gl_FogFragCoord ); 102 | fogColor = osgOcean_UnderwaterFogColor; 103 | 104 | // depth buffer 105 | if(osgOcean_EnableDOF) 106 | { 107 | float depthBlur = computeDepthBlur( gl_FogFragCoord, osgOcean_DOF_Focus, osgOcean_DOF_Near, osgOcean_DOF_Far, osgOcean_DOF_Clamp ); 108 | gl_FragData[1] = vec4(depthBlur); 109 | } 110 | } 111 | else 112 | { 113 | fogFactor = computeFogFactor( osgOcean_AboveWaterFogDensity, gl_FogFragCoord ); 114 | fogColor = osgOcean_AboveWaterFogColor; 115 | 116 | // luminance buffer 117 | if(osgOcean_EnableGlare) 118 | { 119 | gl_FragData[1] = vec4(0.0); 120 | } 121 | } 122 | 123 | // color buffer 124 | gl_FragData[0] = mix( fogColor, final_color, fogFactor ); 125 | } -------------------------------------------------------------------------------- /resources/shaders/terrain.vert: -------------------------------------------------------------------------------- 1 | // osgOcean uniforms 2 | // ------------------- 3 | uniform float osgOcean_WaterHeight; 4 | uniform vec3 osgOcean_Eye; 5 | uniform vec3 osgOcean_UnderwaterAttenuation; 6 | uniform vec4 osgOcean_UnderwaterDiffuse; 7 | uniform bool osgOcean_EnableUnderwaterScattering; 8 | // ------------------ 9 | 10 | uniform vec2 uHeightRange; 11 | uniform float uOneOverHeight; 12 | uniform mat4 osg_ViewMatrixInverse; 13 | 14 | varying float vUnitHeight; 15 | 16 | varying vec3 vLightDir; 17 | varying vec3 vEyeVec; 18 | varying vec3 vExtinction; 19 | varying vec3 vInScattering; 20 | varying vec4 vWorldVertex; 21 | 22 | attribute vec3 aTangent; 23 | 24 | void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering ) 25 | { 26 | float viewDist = length(eye-worldVertex); 27 | 28 | float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0); 29 | 30 | extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0); 31 | 32 | // Need to compute accurate kd constant. 33 | // const vec3 kd = vec3(0.001, 0.001, 0.001); 34 | inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001))); 35 | } 36 | 37 | void main(void) 38 | { 39 | gl_TexCoord[0] = gl_MultiTexCoord0*vec4(16.0,16.0,1.0,1.0); 40 | gl_TexCoord[1] = gl_MultiTexCoord0*vec4(20.0,20.0,1.0,1.0); 41 | gl_TexCoord[2] = gl_MultiTexCoord0*vec4(25.0,25.0,1.0,1.0); 42 | 43 | vec3 vertex = vec3(gl_ModelViewMatrix * gl_Vertex); 44 | vEyeVec = -vertex; 45 | 46 | vec3 n = normalize(gl_NormalMatrix * gl_Normal); 47 | vec3 t = normalize(gl_NormalMatrix * aTangent); 48 | vec3 b = cross(n, t); 49 | 50 | vec3 tmpVec = vec3(gl_LightSource[0].position.xyz); 51 | tmpVec = normalize(tmpVec); 52 | 53 | vLightDir.x = dot(tmpVec, t); 54 | vLightDir.y = dot(tmpVec, b); 55 | vLightDir.z = dot(tmpVec, n); 56 | 57 | tmpVec = -vertex; 58 | vEyeVec.x = dot(tmpVec, t); 59 | vEyeVec.y = dot(tmpVec, b); 60 | vEyeVec.z = dot(tmpVec, n); 61 | 62 | gl_Position = ftransform(); 63 | 64 | gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex; 65 | 66 | gl_FogFragCoord = gl_Position.z; 67 | 68 | float inv = 1.0 / ( uHeightRange.y - (uHeightRange.x+65.0) ); 69 | vUnitHeight = inv * (gl_Vertex.z - (uHeightRange.x+65.0)); 70 | 71 | vWorldVertex = (osg_ViewMatrixInverse*gl_ModelViewMatrix) * gl_Vertex; 72 | 73 | if( osgOcean_EnableUnderwaterScattering ) 74 | { 75 | computeScattering( osgOcean_Eye, vWorldVertex.xyz, vExtinction, vInScattering ); 76 | } 77 | 78 | gl_Position = ftransform(); 79 | } -------------------------------------------------------------------------------- /resources/shaders/terrain_lispsm.frag: -------------------------------------------------------------------------------- 1 | // osgOcean uniforms 2 | // ------------------- 3 | uniform float osgOcean_DOF_Near; 4 | uniform float osgOcean_DOF_Focus; 5 | uniform float osgOcean_DOF_Far; 6 | uniform float osgOcean_DOF_Clamp; 7 | 8 | uniform bool osgOcean_EnableGlare; 9 | uniform bool osgOcean_EnableDOF; 10 | uniform bool osgOcean_EyeUnderwater; 11 | uniform bool osgOcean_EnableUnderwaterScattering; 12 | 13 | uniform float osgOcean_UnderwaterFogDensity; 14 | uniform float osgOcean_AboveWaterFogDensity; 15 | uniform float osgOcean_WaterHeight; 16 | 17 | uniform vec4 osgOcean_UnderwaterFogColor; 18 | uniform vec4 osgOcean_AboveWaterFogColor; 19 | // ------------------- 20 | 21 | uniform sampler2D uTextureMap; 22 | uniform sampler2D uOverlayMap; 23 | uniform sampler2D uNormalMap; 24 | 25 | varying vec3 vLightDir; 26 | varying vec3 vEyeVec; 27 | varying vec3 vExtinction; 28 | varying vec3 vInScattering; 29 | 30 | varying vec4 vWorldVertex; 31 | 32 | varying float vUnitHeight; 33 | 34 | uniform sampler2DShadow shadowTexture; 35 | 36 | float computeDepthBlur(float depth, float focus, float near, float far, float clampval ) 37 | { 38 | float f; 39 | if (depth < focus){ 40 | f = (depth - focus)/(focus - near); 41 | } 42 | else{ 43 | f = (depth - focus)/(far - focus); 44 | f = clamp(f, 0.0, clampval); 45 | } 46 | return f * 0.5 + 0.5; 47 | } 48 | 49 | vec4 lighting( in vec4 colormap, in vec3 N ) 50 | { 51 | vec4 final_color = gl_LightSource[osgOcean_LightID].ambient * colormap; 52 | 53 | float light = shadow2DProj( shadowTexture, gl_TexCoord[7] ).r; 54 | 55 | vec3 L = normalize(vLightDir); 56 | 57 | float lambertTerm = dot(N,L); 58 | 59 | if(lambertTerm > 0.0) 60 | { 61 | final_color += gl_LightSource[osgOcean_LightID].diffuse * lambertTerm * colormap * light; 62 | 63 | vec3 E = normalize(vEyeVec); 64 | vec3 R = reflect(-L, N); 65 | 66 | float specular = pow( max(dot(R, E), 0.0), 2.0 ); 67 | 68 | final_color += gl_LightSource[osgOcean_LightID].specular * specular * light; 69 | } 70 | 71 | return final_color; 72 | } 73 | 74 | float computeFogFactor( float density, float fogCoord ) 75 | { 76 | return exp2(density * fogCoord * fogCoord ); 77 | } 78 | 79 | void main(void) 80 | { 81 | vec4 baseColor = texture2D( uTextureMap, gl_TexCoord[0].st ); 82 | vec4 overlayColor = texture2D( uOverlayMap, gl_TexCoord[1].st ); 83 | vec4 bumpColor = texture2D( uNormalMap, gl_TexCoord[0].st ); 84 | 85 | float unitHeight = clamp( vUnitHeight, 0.0, 1.0); 86 | vec4 textureColor = mix(overlayColor, baseColor, unitHeight); 87 | 88 | vec3 bump = (bumpColor.xyz*2.0)-1.0; 89 | 90 | float fogFactor = 0.0; 91 | vec4 fogColor; 92 | 93 | vec4 final_color = lighting( textureColor, bump ); 94 | 95 | // +2 tweak here as waves peak above average wave height, 96 | // and surface fog becomes visible. 97 | if(osgOcean_EyeUnderwater && vWorldVertex.z < osgOcean_WaterHeight+2.0) 98 | { 99 | // mix in underwater light 100 | if( osgOcean_EnableUnderwaterScattering ) 101 | { 102 | final_color.rgb = final_color.rgb * vExtinction + vInScattering; 103 | } 104 | 105 | fogFactor = computeFogFactor( osgOcean_UnderwaterFogDensity, gl_FogFragCoord ); 106 | fogColor = osgOcean_UnderwaterFogColor; 107 | 108 | // depth buffer 109 | if(osgOcean_EnableDOF) 110 | { 111 | float depthBlur = computeDepthBlur( gl_FogFragCoord, osgOcean_DOF_Focus, osgOcean_DOF_Near, osgOcean_DOF_Far, osgOcean_DOF_Clamp ); 112 | gl_FragData[1] = vec4(depthBlur); 113 | } 114 | } 115 | else 116 | { 117 | fogFactor = computeFogFactor( osgOcean_AboveWaterFogDensity, gl_FogFragCoord ); 118 | fogColor = osgOcean_AboveWaterFogColor; 119 | 120 | // luminance buffer 121 | if(osgOcean_EnableGlare) 122 | { 123 | gl_FragData[1] = vec4(0.0); 124 | } 125 | } 126 | 127 | // color buffer 128 | gl_FragData[0] = mix( fogColor, final_color, fogFactor ); 129 | } -------------------------------------------------------------------------------- /resources/shaders/terrain_lispsm.vert: -------------------------------------------------------------------------------- 1 | // osgOcean uniforms 2 | // ------------------- 3 | uniform float osgOcean_WaterHeight; 4 | uniform vec3 osgOcean_Eye; 5 | uniform vec3 osgOcean_UnderwaterAttenuation; 6 | uniform vec4 osgOcean_UnderwaterDiffuse; 7 | uniform bool osgOcean_EnableUnderwaterScattering; 8 | // ------------------ 9 | 10 | uniform vec2 uHeightRange; 11 | uniform float uOneOverHeight; 12 | uniform mat4 osg_ViewMatrixInverse; 13 | 14 | varying float vUnitHeight; 15 | 16 | varying vec3 vLightDir; 17 | varying vec3 vEyeVec; 18 | varying vec3 vExtinction; 19 | varying vec3 vInScattering; 20 | varying vec4 vWorldVertex; 21 | 22 | attribute vec3 aTangent; 23 | 24 | void computeScattering( in vec3 eye, in vec3 worldVertex, out vec3 extinction, out vec3 inScattering ) 25 | { 26 | float viewDist = length(eye-worldVertex); 27 | 28 | float depth = max(osgOcean_WaterHeight-worldVertex.z, 0.0); 29 | 30 | extinction = exp(-osgOcean_UnderwaterAttenuation*viewDist*2.0); 31 | 32 | // Need to compute accurate kd constant. 33 | // const vec3 kd = vec3(0.001, 0.001, 0.001); 34 | inScattering = osgOcean_UnderwaterDiffuse.rgb * (1.0-extinction*exp(-depth*vec3(0.001))); 35 | } 36 | 37 | void main(void) 38 | { 39 | gl_TexCoord[0] = gl_MultiTexCoord0*vec4(16.0,16.0,1.0,1.0); 40 | gl_TexCoord[1] = gl_MultiTexCoord0*vec4(20.0,20.0,1.0,1.0); 41 | gl_TexCoord[2] = gl_MultiTexCoord0*vec4(25.0,25.0,1.0,1.0); 42 | 43 | vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; 44 | vec3 vertex = vec3(ecPosition); 45 | vEyeVec = -vertex; 46 | 47 | vec3 n = normalize(gl_NormalMatrix * gl_Normal); 48 | vec3 t = normalize(gl_NormalMatrix * aTangent); 49 | vec3 b = cross(n, t); 50 | 51 | vec3 tmpVec = vec3(gl_LightSource[0].position.xyz); 52 | tmpVec = normalize(tmpVec); 53 | 54 | vLightDir.x = dot(tmpVec, t); 55 | vLightDir.y = dot(tmpVec, b); 56 | vLightDir.z = dot(tmpVec, n); 57 | 58 | tmpVec = -vertex; 59 | vEyeVec.x = dot(tmpVec, t); 60 | vEyeVec.y = dot(tmpVec, b); 61 | vEyeVec.z = dot(tmpVec, n); 62 | 63 | gl_Position = ftransform(); 64 | 65 | gl_ClipVertex = ecPosition; 66 | 67 | gl_FogFragCoord = gl_Position.z; 68 | 69 | float inv = 1.0 / ( uHeightRange.y - (uHeightRange.x+65.0) ); 70 | vUnitHeight = inv * (gl_Vertex.z - (uHeightRange.x+65.0)); 71 | 72 | vWorldVertex = (osg_ViewMatrixInverse*gl_ModelViewMatrix) * gl_Vertex; 73 | 74 | if( osgOcean_EnableUnderwaterScattering ) 75 | { 76 | computeScattering( osgOcean_Eye, vWorldVertex.xyz, vExtinction, vInScattering ); 77 | } 78 | 79 | // Generate shadow map coords 80 | gl_TexCoord[7].s = dot( ecPosition, gl_EyePlaneS[7] ); 81 | gl_TexCoord[7].t = dot( ecPosition, gl_EyePlaneT[7] ); 82 | gl_TexCoord[7].p = dot( ecPosition, gl_EyePlaneR[7] ); 83 | gl_TexCoord[7].q = dot( ecPosition, gl_EyePlaneQ[7] ); 84 | 85 | gl_Position = ftransform(); 86 | } -------------------------------------------------------------------------------- /resources/textures/sea_foam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/resources/textures/sea_foam.png -------------------------------------------------------------------------------- /resources/textures/sun_glare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbale/osgocean/f235e99977cb868f9f8e1ec5cb0d74006faf4e26/resources/textures/sun_glare.png -------------------------------------------------------------------------------- /scripts/convert_shaders.py: -------------------------------------------------------------------------------- 1 | # This script is use to convert the shaders found 2 | # within the resources/shaders directory to the native 3 | # .inl format for compiling into the osgOcean source. 4 | # After conversion, it will copy the .inl files into the 5 | # include/osgOcean/shaders/ directory. 6 | 7 | import os 8 | import time 9 | 10 | ############################################### 11 | 12 | def readCopyright(): 13 | copyrightFile = open("copyright_notice.txt","r") 14 | copyright = copyrightFile.readlines() 15 | copyrightFile.close() 16 | return copyright 17 | 18 | ############################################### 19 | 20 | def shaderVarName( shaderName ): 21 | varName = shaderName.replace(".","_") 22 | return varName 23 | 24 | ############################################### 25 | 26 | def isCurrent( shader, header ): 27 | if os.path.isfile( header ): 28 | shaderMod = os.path.getmtime(shader) 29 | headerMod = os.path.getmtime(header) 30 | if shaderMod < headerMod: 31 | return True 32 | return False 33 | 34 | ############################################### 35 | 36 | def createInlShader( shaderFile, shaderVar, headerFile ): 37 | file = open(shaderFile,'r') 38 | lines = file.readlines() 39 | file.close() 40 | 41 | oFile = open( headerFile, "w") 42 | 43 | for line in copyright: 44 | oFile.write(line) 45 | 46 | oFile.write("\nstatic const char " + shaderVar +"[] =") 47 | 48 | for line in lines: 49 | newLine = line.replace("\n","").replace("\r","") 50 | oFile.write('\n\t"'+newLine+'\\n"') 51 | 52 | oFile.write(";\n"); 53 | oFile.flush() 54 | oFile.close() 55 | 56 | ############################################## 57 | 58 | print("\nThis script is used to convert the osgOcean shaders") 59 | print("found within the resources/shaders directory to the") 60 | print("native .inl format for compiling into the osgOcean") 61 | print("source.\n") 62 | print("Once converted, the .inl files will be copied into the") 63 | print("include/osgOcean/shaders/ directory overwriting") 64 | print("existing files.\n") 65 | 66 | confirm = raw_input("Continue? [y/n]: ") 67 | 68 | if confirm == 'n' or confirm == 'N': 69 | exit() 70 | 71 | shaderPath = "../resources/shaders/" 72 | headerPath = "../include/osgOcean/shaders/" 73 | 74 | shaderList = os.listdir( shaderPath ) 75 | 76 | skipped = 0 77 | created = 0 78 | 79 | print("\nProcessing shader files") 80 | print("--------------------------------\n") 81 | 82 | copyright = readCopyright() 83 | 84 | for shader in shaderList: 85 | if shader.find("osgOcean_") > -1: 86 | if shader.rfind(".vert") > -1 or shader.rfind(".frag") > -1: 87 | sVar = shaderVarName(shader) 88 | hName = sVar + ".inl" 89 | hFile = headerPath + hName 90 | sFile = shaderPath + shader 91 | 92 | if isCurrent(sFile,hFile) == True: 93 | skipped += 1 94 | print("[skipped] " + sVar) 95 | else: 96 | createInlShader( sFile, sVar, hFile ) 97 | created += 1 98 | print("[CREATED] " + sVar ) 99 | 100 | print("\n--------------------------------") 101 | print(str(created)+"\tCreated") 102 | print(str(skipped)+"\tUp to date") 103 | print(str(skipped+created)+"\tTotal") 104 | print("--------------------------------") 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /scripts/copyright_notice.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | // ------------------------------------------------------------------------------ 19 | // -- THIS FILE HAS BEEN CREATED AS PART OF THE BUILD PROCESS -- DO NOT MODIFY -- 20 | // ------------------------------------------------------------------------------ 21 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (osgOcean) 2 | add_subdirectory (oceanExample) -------------------------------------------------------------------------------- /src/oceanExample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(HEADER_PATH ${osgOcean_SOURCE_DIR}/include/OceanExample ) 2 | SET(LIB_HEADER_PATH ${osgOcean_SOURCE_DIR}/include ) 3 | 4 | SET( SKYBOX_TEXTURES_1 5 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_clear/down.png 6 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_clear/east.png 7 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_clear/north.png 8 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_clear/south.png 9 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_clear/up.png 10 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_clear/west.png 11 | ) 12 | 13 | SET( SKYBOX_TEXTURES_2 14 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_dusk/down.png 15 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_dusk/east.png 16 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_dusk/north.png 17 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_dusk/south.png 18 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_dusk/up.png 19 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_dusk/west.png 20 | ) 21 | 22 | SET( SKYBOX_TEXTURES_3 23 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_fair_cloudy/down.png 24 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_fair_cloudy/east.png 25 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_fair_cloudy/north.png 26 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_fair_cloudy/south.png 27 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_fair_cloudy/up.png 28 | ${osgOcean_SOURCE_DIR}/demo/textures/sky_fair_cloudy/west.png 29 | ) 30 | 31 | SET( ISLAND_RESOURCES 32 | ${osgOcean_SOURCE_DIR}/demo/island/islands.ive 33 | ) 34 | 35 | SET( BOAT_RESOURCES 36 | ${osgOcean_SOURCE_DIR}/resources/boat/boat.3ds 37 | ) 38 | 39 | SET( EXAMPLE_SHADERS 40 | ${osgOcean_SOURCE_DIR}/resources/shaders/terrain.vert 41 | ${osgOcean_SOURCE_DIR}/resources/shaders/terrain.frag 42 | ${osgOcean_SOURCE_DIR}/resources/shaders/terrain_lispsm.vert 43 | ${osgOcean_SOURCE_DIR}/resources/shaders/terrain_lispsm.frag 44 | ${osgOcean_SOURCE_DIR}/resources/shaders/skydome.vert 45 | ${osgOcean_SOURCE_DIR}/resources/shaders/skydome.frag 46 | ) 47 | 48 | # Adds shaders to the "Shaders" group in visual studio 49 | SOURCE_GROUP( "Shaders" FILES ${EXAMPLE_SHADERS} ) 50 | 51 | INCLUDE_DIRECTORIES( 52 | ${LIB_HEADER_PATH} 53 | ${HEADER_PATH} 54 | ) 55 | 56 | ADD_EXECUTABLE( 57 | 58 | oceanExample 59 | 60 | application.cpp 61 | Scene.cpp 62 | SkyDome.cpp 63 | SphereSegment.cpp 64 | 65 | 66 | ${HEADER_PATH}/SceneEventHandler.h 67 | ${HEADER_PATH}/Scene.h 68 | ${HEADER_PATH}/ScopedTimer.h 69 | ${HEADER_PATH}/SkyDome.h 70 | ${HEADER_PATH}/SphereSegment.h 71 | ${HEADER_PATH}/TextHUD.h 72 | 73 | ${EXAMPLE_SHADERS} 74 | ) 75 | 76 | TARGET_LINK_LIBRARIES( 77 | 78 | 79 | oceanExample 80 | 81 | osgOcean 82 | 83 | debug ${OSG_LIBRARY_DEBUG} 84 | optimized ${OSG_LIBRARY} 85 | 86 | debug ${OSGGA_LIBRARY_DEBUG} 87 | optimized ${OSGGA_LIBRARY} 88 | 89 | debug ${OSGVIEWER_LIBRARY_DEBUG} 90 | optimized ${OSGVIEWER_LIBRARY} 91 | 92 | debug ${OSGDB_LIBRARY_DEBUG} 93 | optimized ${OSGDB_LIBRARY} 94 | 95 | debug ${OSGTEXT_LIBRARY_DEBUG} 96 | optimized ${OSGTEXT_LIBRARY} 97 | 98 | debug ${OSGSHADOW_LIBRARY_DEBUG} 99 | optimized ${OSGSHADOW_LIBRARY} 100 | ) 101 | 102 | INSTALL( 103 | TARGETS oceanExample 104 | RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin 105 | ) 106 | 107 | INSTALL( 108 | FILES ${SKYBOX_TEXTURES_1} 109 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/resources/textures/sky_clear 110 | ) 111 | 112 | INSTALL( 113 | FILES ${SKYBOX_TEXTURES_2} 114 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/resources/textures/sky_dusk 115 | ) 116 | 117 | INSTALL( 118 | FILES ${SKYBOX_TEXTURES_3} 119 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/resources/textures/sky_fair_cloudy 120 | ) 121 | 122 | INSTALL( 123 | FILES ${EXAMPLE_SHADERS} 124 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/resources/shaders 125 | ) 126 | 127 | INSTALL( 128 | FILES ${ISLAND_RESOURCES} 129 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/resources/island 130 | ) 131 | 132 | INSTALL( 133 | FILES ${BOAT_RESOURCES} 134 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/resources/boat 135 | ) 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /src/oceanExample/SkyDome.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #include "SkyDome.h" 19 | #include 20 | 21 | SkyDome::SkyDome( void ) 22 | { 23 | 24 | } 25 | 26 | SkyDome::SkyDome( const SkyDome& copy, const osg::CopyOp& copyop ): 27 | SphereSegment( copy, copyop ) 28 | { 29 | 30 | } 31 | 32 | SkyDome::SkyDome( float radius, unsigned int longSteps, unsigned int latSteps, osg::TextureCubeMap* cubemap ) 33 | { 34 | compute( radius, longSteps, latSteps, 90.f, 180.f, 0.f, 360.f ); 35 | setupStateSet(cubemap); 36 | } 37 | 38 | SkyDome::~SkyDome(void) 39 | { 40 | } 41 | 42 | void SkyDome::create( float radius, unsigned int latSteps, unsigned int longSteps, osg::TextureCubeMap* cubemap ) 43 | { 44 | compute( radius, longSteps, latSteps, 90.f, 180.f, 0.f, 360.f ); 45 | setupStateSet(cubemap); 46 | } 47 | 48 | void SkyDome::setupStateSet( osg::TextureCubeMap* cubemap ) 49 | { 50 | osg::StateSet* ss = new osg::StateSet; 51 | 52 | ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); 53 | ss->setTextureAttributeAndModes( 0, cubemap, osg::StateAttribute::ON ); 54 | ss->setAttributeAndModes( createShader().get(), osg::StateAttribute::ON ); 55 | ss->addUniform( new osg::Uniform("uEnvironmentMap", 0) ); 56 | 57 | setStateSet(ss); 58 | } 59 | 60 | osg::ref_ptr SkyDome::createShader(void) 61 | { 62 | osg::ref_ptr program = new osg::Program; 63 | 64 | // Do not use shaders if they were globally disabled. 65 | if (osgOcean::ShaderManager::instance().areShadersEnabled()) 66 | { 67 | char vertexSource[]= 68 | "varying vec3 vTexCoord;\n" 69 | "\n" 70 | "void main(void)\n" 71 | "{\n" 72 | " gl_Position = ftransform();\n" 73 | " vTexCoord = gl_Vertex.xyz;\n" 74 | "}\n"; 75 | 76 | char fragmentSource[]= 77 | "uniform samplerCube uEnvironmentMap;\n" 78 | "varying vec3 vTexCoord;\n" 79 | "\n" 80 | "void main(void)\n" 81 | "{\n" 82 | " vec3 texcoord = vec3(vTexCoord.x, vTexCoord.y, -vTexCoord.z);\n" 83 | " gl_FragData[0] = textureCube( uEnvironmentMap, texcoord.xzy );\n" 84 | " gl_FragData[0].a = 0.0;\n" 85 | " gl_FragData[1] = vec4(0.0);\n" 86 | "}\n"; 87 | 88 | program->setName( "sky_dome_shader" ); 89 | program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexSource)); 90 | program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentSource)); 91 | } 92 | 93 | return program; 94 | } 95 | -------------------------------------------------------------------------------- /src/oceanExample/SphereSegment.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #include "SphereSegment.h" 19 | 20 | SphereSegment::SphereSegment(void) 21 | {} 22 | 23 | SphereSegment::SphereSegment(float radius, 24 | unsigned int longitudeSteps, 25 | unsigned int lattitudeSteps, 26 | float longStart, 27 | float longEnd, 28 | float latStart, 29 | float latEnd ) 30 | { 31 | compute(radius,longitudeSteps,lattitudeSteps,longStart,longEnd,latStart,latEnd); 32 | } 33 | 34 | SphereSegment::SphereSegment( const SphereSegment& copy, const osg::CopyOp& copyop ): 35 | osg::Geode(copy, copyop) 36 | {} 37 | 38 | SphereSegment::~SphereSegment(void) 39 | { 40 | } 41 | 42 | // 0 >= longStart/longEnd <= 180 43 | // 0 >= latStart/latEnd <= 360 44 | 45 | void SphereSegment::compute( float radius, 46 | unsigned int longitudeSteps, 47 | unsigned int lattitudeSteps, 48 | float longStart, 49 | float longEnd, 50 | float latStart, 51 | float latEnd ) 52 | 53 | { 54 | removeDrawables(0,getNumDrawables()); 55 | 56 | osg::Vec3Array* vertices = new osg::Vec3Array(); 57 | osg::Vec2Array* texcoords = new osg::Vec2Array(); 58 | 59 | double x, y, z, t, p, sin_t, cos_t; 60 | 61 | double longInc = (longEnd - longStart) / (double)longitudeSteps; 62 | double latInc = (latEnd - latStart ) / (double)lattitudeSteps; 63 | 64 | double theta = longStart, phi = latStart; 65 | 66 | float uScale = 1.f / longitudeSteps; 67 | float vScale = 1.f / lattitudeSteps; 68 | 69 | for( unsigned int i = 0; i <= longitudeSteps; ++i) 70 | { 71 | t = osg::DegreesToRadians( theta ); 72 | sin_t = sin(t); 73 | cos_t = cos(t); 74 | 75 | for( unsigned int j = 0; j <= lattitudeSteps; ++j) 76 | { 77 | p = osg::DegreesToRadians( phi ); 78 | 79 | x = radius * sin_t * cos(p); 80 | y = radius * sin_t * sin(p); 81 | z = radius * cos_t; 82 | 83 | vertices->push_back( osg::Vec3( x, y, z ) ); 84 | texcoords->push_back( osg::Vec2( j*vScale, i*uScale ) ); 85 | 86 | phi += latInc; 87 | } 88 | 89 | theta -= longInc; 90 | phi = latStart; 91 | } 92 | 93 | osg::ref_ptr geom = new osg::Geometry(); 94 | 95 | for(unsigned int r = 0; r <= longitudeSteps-1; r += 1) 96 | { 97 | osg::DrawElementsUInt* indices = 98 | new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLE_STRIP, 0 ); 99 | 100 | for(unsigned int c = 0; c <= lattitudeSteps; c += 1 ) 101 | { 102 | indices->push_back( idx( r, c, lattitudeSteps+1 ) ); 103 | indices->push_back( idx( r+1, c, lattitudeSteps+1 ) ); 104 | } 105 | 106 | geom->addPrimitiveSet( indices ); 107 | } 108 | 109 | osg::Vec4Array* colors = new osg::Vec4Array(); 110 | colors->push_back( osg::Vec4( 1.f, 1.f, 1.f, 1.f ) ); 111 | 112 | geom->setVertexArray( vertices ); 113 | geom->setTexCoordArray( 0, texcoords ); 114 | geom->setColorArray( colors ); 115 | geom->setColorBinding( osg::Geometry::BIND_OVERALL ); 116 | 117 | addDrawable( geom.get() ); 118 | } 119 | 120 | osg::Vec2 SphereSegment::sphereMap( osg::Vec3& vertex, float radius) 121 | { 122 | float u, v; 123 | 124 | float TWOPI = osg::PI * 2.f; 125 | 126 | v = acos( vertex.y() / radius ) / osg::PI; 127 | 128 | if (vertex.z() >= 0.f) 129 | u = acos( vertex.x() / (radius * sin( osg::PI*v ) ) ) / TWOPI; 130 | else 131 | u = (osg::PI + acos( vertex.x() / ( radius * sin( osg::PI * v ) ) ) ) / TWOPI; 132 | 133 | return osg::Vec2( u, v ); 134 | } 135 | -------------------------------------------------------------------------------- /src/osgOcean/Cylinder.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #include 19 | 20 | using namespace osgOcean; 21 | 22 | Cylinder::Cylinder( void ): 23 | _radius (1.f), 24 | _height (1.f), 25 | _steps (16), 26 | _hasTop (true), 27 | _hasBottom (true) 28 | { 29 | build(); 30 | } 31 | 32 | Cylinder::Cylinder( float radius, float height, unsigned int steps, bool hasTop, bool hasBottom ) : 33 | _radius (radius), 34 | _height (height), 35 | _steps (steps), 36 | _hasTop (hasTop), 37 | _hasBottom (hasBottom) 38 | { 39 | build(); 40 | } 41 | 42 | Cylinder::Cylinder( const Cylinder& copy, const osg::CopyOp& copyop ): 43 | osg::Geometry (copy, copyop), 44 | _radius (copy._radius), 45 | _height (copy._height), 46 | _steps (copy._steps), 47 | _hasTop (copy._hasTop), 48 | _hasBottom (copy._hasBottom) 49 | { 50 | } 51 | 52 | Cylinder::~Cylinder(void) 53 | { 54 | } 55 | 56 | void Cylinder::build( float radius, float height, unsigned int steps, bool top, bool bottom ) 57 | { 58 | _radius = radius; 59 | _height = height; 60 | _steps = steps; 61 | _hasTop = top; 62 | _hasBottom = bottom; 63 | 64 | build(); 65 | } 66 | 67 | void Cylinder::build( void ) 68 | { 69 | // clear primitives if there are any 70 | if(getNumPrimitiveSets() > 0) 71 | { 72 | removePrimitiveSet(0,getNumPrimitiveSets()); 73 | dirtyDisplayList(); 74 | } 75 | 76 | const float twoPI = osg::PI * 2.f; 77 | const float angleInc = twoPI / (float)_steps; 78 | 79 | osg::Vec3Array* vertices = new osg::Vec3Array(); 80 | 81 | vertices->push_back( osg::Vec3f() ); // bottom centre 82 | 83 | for ( float angle = 0.f; angle <= twoPI; angle += angleInc ) 84 | { 85 | float x1 = _radius * cos(angle); 86 | float y1 = _radius * sin(angle); 87 | 88 | vertices->push_back( osg::Vec3( x1, y1, 0.f ) ); 89 | vertices->push_back( osg::Vec3( x1, y1, _height ) ); 90 | } 91 | 92 | vertices->push_back( osg::Vec3f(0.f, 0.f, _height) ); // top centre 93 | 94 | osg::DrawElementsUInt* indices = 95 | new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLE_STRIP, 0 ); 96 | 97 | for(unsigned int c = 1; c < _steps*2+1; c += 2 ) 98 | { 99 | indices->push_back( c ); 100 | indices->push_back( c+1 ); 101 | } 102 | 103 | indices->push_back(1); 104 | indices->push_back(2); 105 | 106 | addPrimitiveSet( indices ); 107 | 108 | if( _hasBottom ) 109 | { 110 | osg::DrawElementsUInt* fanIndices = 111 | new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLE_FAN, 0 ); 112 | 113 | fanIndices->push_back( 0 ); 114 | 115 | for(int c = _steps*2-1; c >= 1; c -= 2 ) 116 | { 117 | fanIndices->push_back( c ); 118 | } 119 | 120 | fanIndices->push_back( _steps*2-1 ); 121 | 122 | addPrimitiveSet( fanIndices ); 123 | } 124 | 125 | if( _hasTop ) 126 | { 127 | osg::DrawElementsUInt* fanIndices = 128 | new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLE_FAN, 0 ); 129 | 130 | fanIndices->push_back( vertices->size()-1 ); 131 | 132 | for(int c = _steps*2; c >= 1; c -= 2 ) 133 | { 134 | fanIndices->push_back( c ); 135 | } 136 | 137 | fanIndices->push_back( _steps*2 ); 138 | 139 | addPrimitiveSet( fanIndices ); 140 | } 141 | 142 | _colorArray = new osg::Vec4Array(1); 143 | (*_colorArray)[0]=osg::Vec4( 0.f, 0.f, 0.f, 1.0f ); 144 | 145 | setVertexArray( vertices ); 146 | setColorArray( _colorArray.get() ); 147 | setColorBinding( osg::Geometry::BIND_OVERALL ); 148 | setUseDisplayList(true); 149 | } 150 | 151 | void Cylinder::setColor(const osg::Vec4f& color) 152 | { 153 | if(getColorArray()) 154 | { 155 | osg::Vec4Array* colors = static_cast( getColorArray() ); 156 | (*_colorArray)[0] = color; 157 | setColorBinding( osg::Geometry::BIND_OVERALL ); 158 | dirtyDisplayList(); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/osgOcean/MipmapGeometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #include 19 | 20 | namespace osgOcean 21 | { 22 | MipmapGeometry::MipmapGeometry( void ): 23 | _level ( 0 ), 24 | _numLevels ( 0 ), 25 | _resolution ( 0 ), 26 | _rowLen ( 0 ), 27 | _colLen ( 0 ), 28 | _startIdx ( 0 ), 29 | _border ( BORDER_NONE ) 30 | { 31 | 32 | } 33 | 34 | MipmapGeometry::MipmapGeometry( unsigned int level, 35 | unsigned int numLevels, 36 | unsigned int startIdx, 37 | BORDER_TYPE border ): 38 | _level ( level ), 39 | _numLevels ( numLevels ), 40 | _resolution ( level != (numLevels-1) ? 2 << (numLevels-(level+2) ) : 1 ), 41 | _rowLen ( border==BORDER_X || border==BORDER_XY ? _resolution+1 : _resolution), 42 | _colLen ( border==BORDER_Y || border==BORDER_XY ? _resolution+1 : _resolution), 43 | _startIdx ( startIdx ), 44 | _border ( border ) 45 | { 46 | } 47 | 48 | MipmapGeometry::~MipmapGeometry( void ) 49 | { 50 | 51 | } 52 | 53 | MipmapGeometry::MipmapGeometry( const MipmapGeometry& copy, const osg::CopyOp& copyop ): 54 | osg::Geometry ( copy, copyop ), 55 | _level ( copy._level ), 56 | _numLevels ( copy._numLevels ), 57 | _resolution ( copy._resolution ), 58 | _rowLen ( copy._rowLen ), 59 | _colLen ( copy._colLen ), 60 | _startIdx ( copy._startIdx ), 61 | _border ( copy._border ) 62 | { 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/osgOcean/OceanTechnique.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | using namespace osgOcean; 22 | 23 | OceanTechnique::OceanTechnique(void) 24 | :_isDirty ( true ) 25 | ,_isAnimating( true ) 26 | {} 27 | 28 | OceanTechnique::OceanTechnique( const OceanTechnique& copy, const osg::CopyOp& copyop ) 29 | :osg::Geode ( copy, copyop ) 30 | ,_isDirty ( true ) 31 | ,_isAnimating( copy._isAnimating ) 32 | {} 33 | 34 | void OceanTechnique::build(void) 35 | { 36 | osg::notify(osg::DEBUG_INFO) << "OceanTechnique::build() Not Implemented" << std::endl; 37 | } 38 | 39 | float OceanTechnique::getSurfaceHeight(void) const 40 | { 41 | osg::notify(osg::DEBUG_INFO) << "OceanTechnique::getSurfaceHeight() Not Implemented" << std::endl; 42 | return 0.f; 43 | } 44 | 45 | float OceanTechnique::getMaximumHeight(void) const 46 | { 47 | osg::notify(osg::DEBUG_INFO) << "OceanTechnique::getMaximumHeight() Not Implemented" << std::endl; 48 | return 0.f; 49 | } 50 | 51 | /** Check if the ocean surface is visible or not. Basic test is very 52 | simple, subclasses can do a better test. */ 53 | bool OceanTechnique::isVisible( osgUtil::CullVisitor& cv, bool eyeAboveWater ) 54 | { 55 | if (getNodeMask() == 0) return false; 56 | 57 | // Use a cutoff to unconditionally cull ocean surface if we can't see it. 58 | // This test is valid when the eye is close to the horizon, but further up 59 | // it will be too conservative (i.e. it will return true even when the 60 | // surface is not visible because it does the test relative to a horizontal 61 | // plane at the eye position). 62 | osg::Camera* currentCamera = cv.getCurrentRenderBin()->getStage()->getCamera(); 63 | if (currentCamera->getProjectionMatrix()(3,3) == 0.0) // Perspective 64 | { 65 | double fovy, ratio, zNear, zFar; 66 | currentCamera->getProjectionMatrixAsPerspective(fovy, ratio, zNear, zFar); 67 | 68 | static const float cutoff = fovy / 2.0; 69 | osg::Vec3 lookVector = cv.getLookVectorLocal(); 70 | float dotProduct = lookVector * osg::Vec3(0,0,1); 71 | return ( eyeAboveWater && dotProduct < cutoff) || 72 | (!eyeAboveWater && dotProduct > -cutoff); 73 | } 74 | else // Ortho 75 | { 76 | return true; 77 | } 78 | 79 | // A better way would be to check if any of the frustum corners intersect 80 | // the plane at (0,0,ocean_height) with normal (0,0,1), and if not then 81 | // return true. 82 | } 83 | 84 | void OceanTechnique::addResourcePaths(void) 85 | { 86 | const std::string shaderPath = "resources/shaders/"; 87 | const std::string texturePath = "resources/textures/"; 88 | 89 | osgDB::FilePathList& pathList = osgDB::Registry::instance()->getDataFilePathList(); 90 | 91 | bool shaderPathPresent = false; 92 | bool texturePathPresent = false; 93 | 94 | for(unsigned int i = 0; i < pathList.size(); ++i ) 95 | { 96 | if( pathList.at(i).compare(shaderPath) == 0 ) 97 | shaderPathPresent = true; 98 | 99 | if( pathList.at(i).compare(texturePath) == 0 ) 100 | texturePathPresent = true; 101 | } 102 | 103 | if(!texturePathPresent) 104 | pathList.push_back(texturePath); 105 | 106 | if(!shaderPathPresent) 107 | pathList.push_back(shaderPath); 108 | } 109 | 110 | // -------------------------------------------------------- 111 | // EventHandler implementation 112 | // -------------------------------------------------------- 113 | 114 | OceanTechnique::EventHandler::EventHandler(OceanTechnique* oceanSurface) 115 | :_oceanSurface(oceanSurface) 116 | { 117 | } 118 | 119 | bool OceanTechnique::EventHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) 120 | { 121 | if (ea.getHandled()) return false; 122 | 123 | // Nothing to do 124 | 125 | return false; 126 | } 127 | 128 | void OceanTechnique::EventHandler::getUsage(osg::ApplicationUsage& usage) const 129 | {} 130 | -------------------------------------------------------------------------------- /src/osgOcean/ScreenAlignedQuad.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the osgOcean library 3 | * 4 | * Copyright (C) 2009 Kim Bale 5 | * Copyright (C) 2009 The University of Hull, UK 6 | * 7 | * This program is free software; you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the Free Software 9 | * Foundation; either version 3 of the License, or (at your option) any later 10 | * version. 11 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 15 | * http://www.gnu.org/copyleft/lesser.txt. 16 | */ 17 | 18 | #include 19 | 20 | using namespace osgOcean; 21 | 22 | ScreenAlignedQuad::ScreenAlignedQuad(void) 23 | { 24 | } 25 | 26 | ScreenAlignedQuad::ScreenAlignedQuad( const osg::Vec3f& corner, const osg::Vec2f& dims, const osg::Vec2s& textureSize ) 27 | { 28 | build( corner, dims, textureSize ); 29 | } 30 | 31 | ScreenAlignedQuad::ScreenAlignedQuad( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture ) 32 | { 33 | if(texture) 34 | build( corner, dims, texture ); 35 | } 36 | 37 | ScreenAlignedQuad::ScreenAlignedQuad( const ScreenAlignedQuad ©, const osg::CopyOp ©op): 38 | osg::Geometry(copy,copyop) 39 | { 40 | } 41 | 42 | void ScreenAlignedQuad::build( const osg::Vec3f& corner, const osg::Vec2f& dims, const osg::Vec2s& textureSize ) 43 | { 44 | osg::Vec3Array* coords = new osg::Vec3Array(4); 45 | (*coords)[0] = corner+osg::Vec3f(0.f, dims.y(), 0.f); 46 | (*coords)[1] = corner; 47 | (*coords)[2] = corner+osg::Vec3f(dims.x(), 0.f, 0.f); 48 | (*coords)[3] = corner+osg::Vec3f(dims.x(), dims.y(), 0.f); 49 | setVertexArray(coords); 50 | 51 | osg::Vec2Array* tcoords = new osg::Vec2Array(4); 52 | (*tcoords)[0].set(0.f, textureSize.y()); 53 | (*tcoords)[1].set(0.f, 0.f); 54 | (*tcoords)[2].set(textureSize.x(), 0.f); 55 | (*tcoords)[3].set(textureSize.x(), textureSize.y()); 56 | setTexCoordArray(0,tcoords); 57 | 58 | osg::Vec4Array* colours = new osg::Vec4Array(1); 59 | (*colours)[0].set(1.0f,1.0f,1.0,1.0f); 60 | setColorArray(colours); 61 | setColorBinding(osg::Geometry::BIND_OVERALL); 62 | 63 | osg::Vec3Array* normals = new osg::Vec3Array(1); 64 | (*normals)[0] = osg::Vec3f(0.f, -1.f, 0.f); 65 | (*normals)[0].normalize(); 66 | setNormalArray(normals); 67 | setNormalBinding(osg::Geometry::BIND_OVERALL); 68 | 69 | addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); 70 | 71 | getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); 72 | getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF ); 73 | } 74 | 75 | void ScreenAlignedQuad::build( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture ) 76 | { 77 | if(texture) 78 | { 79 | osg::Vec2s texSize( texture->getTextureWidth(), texture->getTextureHeight() ); 80 | build(corner, dims, texSize); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/osgOcean/Version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | const char* osgOceanGetVersion() 6 | { 7 | static char ocean_version[256]; 8 | static int ocean_version_init = 1; 9 | 10 | if( ocean_version_init ) 11 | { 12 | if( OSGOCEAN_VERSION_REVISION == 0 ) 13 | sprintf( ocean_version, "%d.%d.%d", OSGOCEAN_VERSION_MAJOR, OSGOCEAN_VERSION_MINOR, OSGOCEAN_VERSION_RELEASE ); 14 | else 15 | sprintf( ocean_version, "%d.%d.%d-%d", OSGOCEAN_VERSION_MAJOR, OSGOCEAN_VERSION_MINOR, OSGOCEAN_VERSION_RELEASE, OSGOCEAN_VERSION_REVISION ); 16 | 17 | ocean_version_init = 0; 18 | } 19 | 20 | return ocean_version; 21 | } 22 | 23 | const char* osgOceanGetLibraryName() 24 | { 25 | return "osgOcean Library"; 26 | } --------------------------------------------------------------------------------