├── .gitignore ├── License.md ├── README.markdown ├── addon_config.mk ├── data └── ofxVolumetrics │ └── shaders │ ├── gl2 │ ├── raycast.frag │ └── raycast.vert │ └── gl3 │ ├── raycast.frag │ └── raycast.vert ├── ofxVolumetricsExample ├── addons.make ├── bin │ └── data │ │ ├── background.png │ │ └── volumes │ │ └── head │ │ ├── cthead-8bit001.tif │ │ ├── cthead-8bit002.tif │ │ ├── cthead-8bit003.tif │ │ ├── cthead-8bit004.tif │ │ ├── cthead-8bit005.tif │ │ ├── cthead-8bit006.tif │ │ ├── cthead-8bit007.tif │ │ ├── cthead-8bit008.tif │ │ ├── cthead-8bit009.tif │ │ ├── cthead-8bit010.tif │ │ ├── cthead-8bit011.tif │ │ ├── cthead-8bit012.tif │ │ ├── cthead-8bit013.tif │ │ ├── cthead-8bit014.tif │ │ ├── cthead-8bit015.tif │ │ ├── cthead-8bit016.tif │ │ ├── cthead-8bit017.tif │ │ ├── cthead-8bit018.tif │ │ ├── cthead-8bit019.tif │ │ ├── cthead-8bit020.tif │ │ ├── cthead-8bit021.tif │ │ ├── cthead-8bit022.tif │ │ ├── cthead-8bit023.tif │ │ ├── cthead-8bit024.tif │ │ ├── cthead-8bit025.tif │ │ ├── cthead-8bit026.tif │ │ ├── cthead-8bit027.tif │ │ ├── cthead-8bit028.tif │ │ ├── cthead-8bit029.tif │ │ ├── cthead-8bit030.tif │ │ ├── cthead-8bit031.tif │ │ ├── cthead-8bit032.tif │ │ ├── cthead-8bit033.tif │ │ ├── cthead-8bit034.tif │ │ ├── cthead-8bit035.tif │ │ ├── cthead-8bit036.tif │ │ ├── cthead-8bit037.tif │ │ ├── cthead-8bit038.tif │ │ ├── cthead-8bit039.tif │ │ ├── cthead-8bit040.tif │ │ ├── cthead-8bit041.tif │ │ ├── cthead-8bit042.tif │ │ ├── cthead-8bit043.tif │ │ ├── cthead-8bit044.tif │ │ ├── cthead-8bit045.tif │ │ ├── cthead-8bit046.tif │ │ ├── cthead-8bit047.tif │ │ ├── cthead-8bit048.tif │ │ ├── cthead-8bit049.tif │ │ ├── cthead-8bit050.tif │ │ ├── cthead-8bit051.tif │ │ ├── cthead-8bit052.tif │ │ ├── cthead-8bit053.tif │ │ ├── cthead-8bit054.tif │ │ ├── cthead-8bit055.tif │ │ ├── cthead-8bit056.tif │ │ ├── cthead-8bit057.tif │ │ ├── cthead-8bit058.tif │ │ ├── cthead-8bit059.tif │ │ ├── cthead-8bit060.tif │ │ ├── cthead-8bit061.tif │ │ ├── cthead-8bit062.tif │ │ ├── cthead-8bit063.tif │ │ ├── cthead-8bit064.tif │ │ ├── cthead-8bit065.tif │ │ ├── cthead-8bit066.tif │ │ ├── cthead-8bit067.tif │ │ ├── cthead-8bit068.tif │ │ ├── cthead-8bit069.tif │ │ ├── cthead-8bit070.tif │ │ ├── cthead-8bit071.tif │ │ ├── cthead-8bit072.tif │ │ ├── cthead-8bit073.tif │ │ ├── cthead-8bit074.tif │ │ ├── cthead-8bit075.tif │ │ ├── cthead-8bit076.tif │ │ ├── cthead-8bit077.tif │ │ ├── cthead-8bit078.tif │ │ ├── cthead-8bit079.tif │ │ ├── cthead-8bit080.tif │ │ ├── cthead-8bit081.tif │ │ ├── cthead-8bit082.tif │ │ ├── cthead-8bit083.tif │ │ ├── cthead-8bit084.tif │ │ ├── cthead-8bit085.tif │ │ ├── cthead-8bit086.tif │ │ ├── cthead-8bit087.tif │ │ ├── cthead-8bit088.tif │ │ ├── cthead-8bit089.tif │ │ ├── cthead-8bit090.tif │ │ ├── cthead-8bit091.tif │ │ ├── cthead-8bit092.tif │ │ ├── cthead-8bit093.tif │ │ ├── cthead-8bit094.tif │ │ ├── cthead-8bit095.tif │ │ ├── cthead-8bit096.tif │ │ ├── cthead-8bit097.tif │ │ ├── cthead-8bit098.tif │ │ └── cthead-8bit099.tif └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── ofxaddons_thumbnail.png └── src ├── ofxImageSequencePlayer.h ├── ofxTexture3d.cpp ├── ofxTexture3d.h ├── ofxVolumetrics.cpp └── ofxVolumetrics.h /.gitignore: -------------------------------------------------------------------------------- 1 | bin/.app 2 | bin/data/users 3 | bin/.exe 4 | bin/.dll 5 | *.mp4 6 | !spec/*.mp4 7 | *.app 8 | *.exe 9 | !spec/*.app 10 | !spec/*.exe 11 | !spec/*.dll 12 | *.dll 13 | obj/ 14 | .DS_Store 15 | ## Ignore Visual Studio temporary files, build results, and 16 | ## files generated by popular Visual Studio add-ons. 17 | ## 18 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 19 | 20 | # User-specific files 21 | *.suo 22 | *.user 23 | *.userosscache 24 | *.sln.docstates 25 | 26 | # User-specific files (MonoDevelop/Xamarin Studio) 27 | *.userprefs 28 | 29 | # Build results 30 | [Dd]ebug/ 31 | [Dd]ebugPublic/ 32 | [Rr]elease/ 33 | [Rr]eleases/ 34 | x64/ 35 | x86/ 36 | bld/ 37 | [Oo]bj/ 38 | [Ll]og/ 39 | 40 | # Visual Studio 2015/2017 cache/options directory 41 | .vs/ 42 | # Uncomment if you have tasks that create the project's static files in wwwroot 43 | #wwwroot/ 44 | 45 | # Visual Studio 2017 auto generated files 46 | Generated\ Files/ 47 | 48 | # MSTest test Results 49 | [Tt]est[Rr]esult*/ 50 | [Bb]uild[Ll]og.* 51 | 52 | # NUNIT 53 | *.VisualState.xml 54 | TestResult.xml 55 | 56 | # Build Results of an ATL Project 57 | [Dd]ebugPS/ 58 | [Rr]eleasePS/ 59 | dlldata.c 60 | 61 | # Benchmark Results 62 | BenchmarkDotNet.Artifacts/ 63 | 64 | # .NET Core 65 | project.lock.json 66 | project.fragment.lock.json 67 | artifacts/ 68 | **/Properties/launchSettings.json 69 | 70 | # StyleCop 71 | StyleCopReport.xml 72 | 73 | # Files built by Visual Studio 74 | *_i.c 75 | *_p.c 76 | *_i.h 77 | *.ilk 78 | *.meta 79 | *.obj 80 | *.pch 81 | *.pdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *.log 92 | *.vspscc 93 | *.vssscc 94 | .builds 95 | *.pidb 96 | *.svclog 97 | *.scc 98 | 99 | # Chutzpah Test files 100 | _Chutzpah* 101 | 102 | # Visual C++ cache files 103 | ipch/ 104 | *.aps 105 | *.ncb 106 | *.opendb 107 | *.opensdf 108 | *.sdf 109 | *.cachefile 110 | *.VC.db 111 | *.VC.VC.opendb 112 | 113 | # Visual Studio profiler 114 | *.psess 115 | *.vsp 116 | *.vspx 117 | *.sap 118 | 119 | # Visual Studio Trace Files 120 | *.e2e 121 | 122 | # TFS 2012 Local Workspace 123 | $tf/ 124 | 125 | # Guidance Automation Toolkit 126 | *.gpState 127 | 128 | # ReSharper is a .NET coding add-in 129 | _ReSharper*/ 130 | *.[Rr]e[Ss]harper 131 | *.DotSettings.user 132 | 133 | # JustCode is a .NET coding add-in 134 | .JustCode 135 | 136 | # TeamCity is a build add-in 137 | _TeamCity* 138 | 139 | # DotCover is a Code Coverage Tool 140 | *.dotCover 141 | 142 | # AxoCover is a Code Coverage Tool 143 | .axoCover/* 144 | !.axoCover/settings.json 145 | 146 | # Visual Studio code coverage results 147 | *.coverage 148 | *.coveragexml 149 | 150 | # NCrunch 151 | _NCrunch_* 152 | .*crunch*.local.xml 153 | nCrunchTemp_* 154 | 155 | # MightyMoose 156 | *.mm.* 157 | AutoTest.Net/ 158 | 159 | # Web workbench (sass) 160 | .sass-cache/ 161 | 162 | # Installshield output folder 163 | [Ee]xpress/ 164 | 165 | # DocProject is a documentation generator add-in 166 | DocProject/buildhelp/ 167 | DocProject/Help/*.HxT 168 | DocProject/Help/*.HxC 169 | DocProject/Help/*.hhc 170 | DocProject/Help/*.hhk 171 | DocProject/Help/*.hhp 172 | DocProject/Help/Html2 173 | DocProject/Help/html 174 | 175 | # Click-Once directory 176 | publish/ 177 | 178 | # Publish Web Output 179 | *.[Pp]ublish.xml 180 | *.azurePubxml 181 | # Note: Comment the next line if you want to checkin your web deploy settings, 182 | # but database connection strings (with potential passwords) will be unencrypted 183 | *.pubxml 184 | *.publishproj 185 | 186 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 187 | # checkin your Azure Web App publish settings, but sensitive information contained 188 | # in these scripts will be unencrypted 189 | PublishScripts/ 190 | 191 | # NuGet Packages 192 | *.nupkg 193 | # The packages folder can be ignored because of Package Restore 194 | **/[Pp]ackages/* 195 | # except build/, which is used as an MSBuild target. 196 | !**/[Pp]ackages/build/ 197 | # Uncomment if necessary however generally it will be regenerated when needed 198 | #!**/[Pp]ackages/repositories.config 199 | # NuGet v3's project.json files produces more ignorable files 200 | *.nuget.props 201 | *.nuget.targets 202 | 203 | # Microsoft Azure Build Output 204 | csx/ 205 | *.build.csdef 206 | 207 | # Microsoft Azure Emulator 208 | ecf/ 209 | rcf/ 210 | 211 | # Windows Store app package directories and files 212 | AppPackages/ 213 | BundleArtifacts/ 214 | Package.StoreAssociation.xml 215 | _pkginfo.txt 216 | *.appx 217 | 218 | # Visual Studio cache files 219 | # files ending in .cache can be ignored 220 | *.[Cc]ache 221 | # but keep track of directories ending in .cache 222 | !*.[Cc]ache/ 223 | 224 | # Others 225 | ClientBin/ 226 | ~$* 227 | *~ 228 | *.dbmdl 229 | *.dbproj.schemaview 230 | *.jfm 231 | *.pfx 232 | *.publishsettings 233 | orleans.codegen.cs 234 | 235 | # Including strong name files can present a security risk 236 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 237 | #*.snk 238 | 239 | # Since there are multiple workflows, uncomment next line to ignore bower_components 240 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 241 | #bower_components/ 242 | 243 | # RIA/Silverlight projects 244 | Generated_Code/ 245 | 246 | # Backup & report files from converting an old project file 247 | # to a newer Visual Studio version. Backup files are not needed, 248 | # because we have git ;-) 249 | _UpgradeReport_Files/ 250 | Backup*/ 251 | UpgradeLog*.XML 252 | UpgradeLog*.htm 253 | ServiceFabricBackup/ 254 | 255 | # SQL Server files 256 | *.mdf 257 | *.ldf 258 | *.ndf 259 | 260 | # Business Intelligence projects 261 | *.rdl.data 262 | *.bim.layout 263 | *.bim_*.settings 264 | 265 | # Microsoft Fakes 266 | FakesAssemblies/ 267 | 268 | # GhostDoc plugin setting file 269 | *.GhostDoc.xml 270 | 271 | # Node.js Tools for Visual Studio 272 | .ntvs_analysis.dat 273 | node_modules/ 274 | 275 | # TypeScript v1 declaration files 276 | typings/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # JetBrains Rider 303 | .idea/ 304 | *.sln.iml 305 | 306 | # CodeRush 307 | .cr/ 308 | 309 | # Python Tools for Visual Studio (PTVS) 310 | __pycache__/ 311 | *.pyc 312 | 313 | # Cake - Uncomment if you are using it 314 | # tools/** 315 | # !tools/packages.config 316 | 317 | # Tabs Studio 318 | *.tss 319 | 320 | # Telerik's JustMock configuration file 321 | *.jmconfig 322 | 323 | # BizTalk build output 324 | *.btp.cs 325 | *.btm.cs 326 | *.odx.cs 327 | *.xsd.cs 328 | 329 | # OpenCover UI analysis results 330 | OpenCover/ 331 | 332 | # Azure Stream Analytics local run output 333 | ASALocalRun/ 334 | 335 | # MSBuild Binary and Structured Log 336 | *.binlog 337 | 338 | 339 | ################## oF 340 | 341 | config.make 342 | Makefile 343 | 344 | #vs 345 | icon.rc 346 | *.sln 347 | *.vcxproj 348 | *.vcxproj.filters 349 | *.vcxproj.user 350 | bin/* 351 | !bin/data 352 | 353 | *.exp 354 | *.lib 355 | 356 | #xcode 357 | *.plist 358 | Project.xcconfig 359 | *.xcodeproj 360 | 361 | !gitkeep 362 | 363 | #windows 364 | Desktop.ini 365 | 366 | #examples 367 | ofxVolumetricsExample/bin/data/ofxVolumetrics -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | ofxVolumetrics is available under the [MIT License](https://secure.wikimedia.org/wikipedia/en/wiki/Mit_license). 2 | 3 | Copyright (c) 2012 - Timothy Scaffidi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | ofxVolumetrics 2 | ============== 3 | 4 | Description 5 | ----------- 6 | 7 | Render volumetric data on the GPU using GLSL and openFrameworks. 8 | 9 | Written by Timothy Scaffidi (http://timothyscaffidi.com) 10 | Volumetric rendering algorithm adapted from Peter Trier (http://www.daimi.au.dk/~trier/?page_id=98) 11 | Single pass rendering method adapted from Phillip Rideout (http://prideout.net/blog/?p=64) 12 | 13 | Usage 14 | ----- 15 | 16 | ~~copy or make symbolic links to the shaders in your app's bin/data/shaders folder.~~ 17 | Shader source is now embedded into the addon. No need for shader files now. 18 | 19 | *setup:* 20 | `void setup(int w, int h, int d, ofVec3f voxelSize, bool usePowerOfTwoTexSize)`; 21 | `voxelSize` is the size of each voxel, W:H:D, used for stretching the volume, think pixel aspect ratio in video. If there is a data set that looks squashed with 1:1:1, try 1:1:2. `usePowerOfTwoTexSize` sets the cropped power-of-two texture mode. This mode will allocate a volume with power-of-two sized texture memory. For example, if you ask for 640x480x200, it will create a volume of size 1024x512x256, but only render a 640x480x200 voxel portion. This mode uses more memory but can greatly increase performance on some hardware. You may want to use this mode if resizing your data to power-of-two sizes is not possible. 22 | 23 | *load with data:* 24 | Create a voxel buffer `unsigned char array`. This must be RGBA! rendering voxels without an alpha channel defeats the point. 25 | 26 | `void updateVolumeData(unsigned char * data, int w, int h, int d, int xOffset, int yOffset, int zOffset);` 27 | Upload the entire volume at once, or sub-portions of the volume using the x y and z offset amounts to change the size of upload. 28 | Note that moving large amounts of data from system memory to GFX memory is quite slow! Updating the entire volume every frame will be very slow, only update what has changed if you want to do animation. 29 | 30 | *Render:* 31 | Perform any transformations as per usual, and draw the volume as you would any other 3d object. in this case, a box. 32 | 'void drawVolume(float x, float y, float z, float size, int zTexOffset);' 33 | 'zTexOffset' is used to slide the texture coordinates around on the z axis, which may be useful for animation by uploading one slice at a time. 34 | -------------------------------------------------------------------------------- /addon_config.mk: -------------------------------------------------------------------------------- 1 | # All variables and this file are optional, if they are not present the PG and the 2 | # makefiles will try to parse the correct values from the file system. 3 | # 4 | # Variables that specify exclusions can use % as a wildcard to specify that anything in 5 | # that position will match. A partial path can also be specified to, for example, exclude 6 | # a whole folder from the parsed paths from the file system 7 | # 8 | # Variables can be specified using = or += 9 | # = will clear the contents of that variable both specified from the file or the ones parsed 10 | # from the file system 11 | # += will add the values to the previous ones in the file or the ones parsed from the file 12 | # system 13 | # 14 | # The PG can be used to detect errors in this file, just create a new project with this addon 15 | # and the PG will write to the console the kind of error and in which line it is 16 | 17 | meta: 18 | ADDON_NAME = ofxAddonTemplate 19 | ADDON_DESCRIPTION = ofxAddonTemplate is amazing! 20 | ADDON_AUTHOR = @yournamehere 21 | ADDON_TAGS = "addon" "template" 22 | ADDON_URL = http://github.com/yournamehere/ofxAddonTemplate 23 | 24 | common: 25 | # dependencies with other addons, a list of them separated by spaces 26 | # or use += in several lines 27 | # ADDON_DEPENDENCIES = 28 | 29 | # include search paths, this will be usually parsed from the file system 30 | # but if the addon or addon libraries need special search paths they can be 31 | # specified here separated by spaces or one per line using += 32 | # ADDON_INCLUDES = 33 | 34 | # any special flag that should be passed to the compiler when using this 35 | # addon 36 | # ADDON_CFLAGS = 37 | 38 | # any special flag that should be passed to the compiler for c++ files when 39 | # using this addon 40 | # ADDON_CPPFLAGS = 41 | 42 | # any special flag that should be passed to the linker when using this 43 | # addon, also used for system libraries with -lname 44 | # ADDON_LDFLAGS = 45 | 46 | # source files, these will be usually parsed from the file system looking 47 | # in the src folders in libs and the root of the addon. if your addon needs 48 | # to include files in different places or a different set of files per platform 49 | # they can be specified here 50 | # ADDON_SOURCES = 51 | 52 | # source files that will be included as C files explicitly 53 | # ADDON_C_SOURCES = 54 | 55 | # source files that will be included as header files explicitly 56 | # ADDON_HEADER_SOURCES = 57 | 58 | # source files that will be included as c++ files explicitly 59 | # ADDON_CPP_SOURCES = 60 | 61 | # source files that will be included as objective c files explicitly 62 | # ADDON_OBJC_SOURCES = 63 | 64 | # derines that will be passed to the compiler when including this addon 65 | # ADDON_DEFINES 66 | 67 | # some addons need resources to be copied to the bin/data folder of the project 68 | # specify here any files that need to be copied, you can use wildcards like * and ? 69 | ADDON_DATA = data/ofxVolumetrics 70 | 71 | # when parsing the file system looking for libraries exclude this for all or 72 | # a specific platform 73 | # ADDON_LIBS_EXCLUDE = 74 | 75 | # binary libraries, these will be usually parsed from the file system but some 76 | # libraries need to passed to the linker in a specific order/ 77 | # 78 | # For example in the ofxOpenCV addon we do something like this: 79 | # 80 | # ADDON_LIBS = 81 | # ADDON_LIBS += libs/opencv/lib/linuxarmv6l/libopencv_legacy.a 82 | # ADDON_LIBS += libs/opencv/lib/linuxarmv6l/libopencv_calib3d.a 83 | # ... 84 | 85 | 86 | linux64: 87 | # linux only, any library that should be included in the project using 88 | # pkg-config 89 | # ADDON_PKG_CONFIG_LIBRARIES = 90 | vs: 91 | # After compiling copy the following dynamic libraries to the executable directory 92 | # only windows visual studio 93 | # ADDON_DLLS_TO_COPY = 94 | 95 | linuxarmv6l: 96 | linuxarmv7l: 97 | android/armeabi: 98 | android/armeabi-v7a: 99 | osx: 100 | # osx/iOS only, any framework that should be included in the project 101 | # ADDON_FRAMEWORKS = 102 | ios: 103 | tvos: 104 | 105 | -------------------------------------------------------------------------------- /data/ofxVolumetrics/shaders/gl2/raycast.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | #extension GL_ARB_texture_rectangle : enable 3 | 4 | varying vec3 cameraPosition; 5 | 6 | uniform sampler3D volume_tex; 7 | uniform vec3 vol_d; 8 | uniform vec3 vol_d_pot; 9 | uniform vec2 bg_d; 10 | uniform float zoffset; 11 | uniform float quality; 12 | uniform float threshold; 13 | uniform float density; 14 | 15 | struct Ray 16 | { 17 | vec3 Origin; 18 | vec3 Dir; 19 | }; 20 | 21 | struct BoundingBox 22 | { 23 | vec3 Min; 24 | vec3 Max; 25 | }; 26 | 27 | bool IntersectBox(Ray r, BoundingBox box, out float t0, out float t1) 28 | { 29 | vec3 invR = 1.0 / r.Dir; 30 | vec3 tbot = invR * (box.Min - r.Origin); 31 | vec3 ttop = invR * (box.Max - r.Origin); 32 | vec3 tmin = min(ttop, tbot); 33 | vec3 tmax = max(ttop, tbot); 34 | vec2 t = max(tmin.xx, tmin.yz); 35 | t0 = max(t.x, t.y); 36 | t = min(tmax.xx, tmax.yz); 37 | t1 = min(t.x, t.y); 38 | return t0 <= t1; 39 | } 40 | 41 | void main() 42 | { 43 | vec3 minv = vec3(0.) + 1. / vol_d_pot; 44 | vec3 maxv = (vol_d / vol_d_pot) - 1. / vol_d_pot; 45 | vec3 vec; 46 | vec3 vold = (maxv - minv) * vol_d; 47 | float vol_l = length(vold); 48 | 49 | vec4 col_acc = vec4(0, 0, 0, 0); 50 | vec3 zOffsetVec = vec3(0.0, 0.0, zoffset / vol_d_pot.z); 51 | vec3 backPos = gl_TexCoord[0].xyz; 52 | vec3 lookVec = normalize(backPos - cameraPosition); 53 | 54 | Ray eye = Ray(cameraPosition, lookVec); 55 | BoundingBox box = BoundingBox(vec3(0.), vec3(1.)); 56 | 57 | float tnear, tfar; 58 | IntersectBox(eye, box, tnear, tfar); 59 | if (tnear < 0.15) tnear = 0.15; 60 | if (tnear > tfar) discard; 61 | 62 | vec3 rayStart = (eye.Origin + eye.Dir * tnear) * (maxv - minv) + minv; //vol_d/vol_d_pot; 63 | vec3 rayStop = (eye.Origin + eye.Dir * tfar) * (maxv - minv) + minv; //vol_d/vol_d_pot; 64 | 65 | vec3 dir = rayStop - rayStart; // starting position of the ray 66 | 67 | vec = rayStart; 68 | float dl = length(dir); 69 | if (dl == clamp(dl, 0., vol_l)) 70 | { 71 | int steps = int(floor(length(vold * dir) * quality)); 72 | vec3 delta_dir = dir / float(steps); 73 | vec4 color_sample; 74 | float aScale = density / quality; 75 | 76 | float random = fract(sin(gl_FragCoord.x * 12.9898 + gl_FragCoord.y * 78.233) * 43758.5453); 77 | vec += delta_dir * random; 78 | 79 | //raycast 80 | for (int i = 0; i < steps; i++) 81 | { 82 | vec3 vecz = vec + zOffsetVec; 83 | if (vecz.z > maxv.z) 84 | { 85 | vecz.z -= maxv.z; 86 | } 87 | 88 | color_sample = texture3D(volume_tex, vecz); 89 | if (color_sample.a > threshold) 90 | { 91 | float oneMinusAlpha = 1. - col_acc.a; 92 | color_sample.a *= aScale; 93 | col_acc.rgb = mix(col_acc.rgb, color_sample.rgb * color_sample.a, oneMinusAlpha); 94 | col_acc.a += color_sample.a * oneMinusAlpha; 95 | col_acc.rgb /= col_acc.a; 96 | if (col_acc.a >= 1.0) 97 | { 98 | break; // terminate if opacity > 1 99 | } 100 | } 101 | vec += delta_dir; 102 | } 103 | } 104 | 105 | gl_FragColor = col_acc; 106 | } -------------------------------------------------------------------------------- /data/ofxVolumetrics/shaders/gl2/raycast.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | varying vec3 cameraPosition; 4 | 5 | void main() 6 | { 7 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 8 | 9 | // ofMesh / ofVboMesh only supports 2d texture coordinates 10 | // as our vertex coordinates are normalized (0..1) 11 | // we can reuse them as 3d texture coordinates 12 | gl_TexCoord[0] = gl_Vertex; 13 | 14 | cameraPosition = (gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0)).xyz; 15 | } -------------------------------------------------------------------------------- /data/ofxVolumetrics/shaders/gl3/raycast.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | //#extension GL_ARB_texture_rectangle : enable 3 | 4 | in vec3 v_texcoord; 5 | in vec3 v_cameraPosition; 6 | 7 | out vec4 out_color; 8 | 9 | uniform sampler3D volume_tex; 10 | uniform vec3 vol_d; 11 | uniform vec3 vol_d_pot; 12 | uniform vec2 bg_d; 13 | uniform float zoffset; 14 | uniform float quality; 15 | uniform float threshold; 16 | uniform float density; 17 | 18 | struct Ray 19 | { 20 | vec3 Origin; 21 | vec3 Dir; 22 | }; 23 | 24 | struct BoundingBox 25 | { 26 | vec3 Min; 27 | vec3 Max; 28 | }; 29 | 30 | bool IntersectBox(Ray r, BoundingBox box, out float t0, out float t1) 31 | { 32 | vec3 invR = 1.0 / r.Dir; 33 | vec3 tbot = invR * (box.Min - r.Origin); 34 | vec3 ttop = invR * (box.Max - r.Origin); 35 | vec3 tmin = min(ttop, tbot); 36 | vec3 tmax = max(ttop, tbot); 37 | vec2 t = max(tmin.xx, tmin.yz); 38 | t0 = max(t.x, t.y); 39 | t = min(tmax.xx, tmax.yz); 40 | t1 = min(t.x, t.y); 41 | return t0 <= t1; 42 | } 43 | 44 | void main() 45 | { 46 | vec3 minv = vec3(0.) + 1. / vol_d_pot; 47 | vec3 maxv = (vol_d / vol_d_pot) - 1. / vol_d_pot; 48 | vec3 vec; 49 | vec3 vold = (maxv - minv) * vol_d; 50 | float vol_l = length(vold); 51 | 52 | vec4 col_acc = vec4(0, 0, 0, 0); 53 | vec3 zOffsetVec = vec3(0.0, 0.0, zoffset / vol_d_pot.z); 54 | vec3 backPos = v_texcoord; 55 | vec3 lookVec = normalize(backPos - v_cameraPosition); 56 | 57 | Ray eye = Ray(v_cameraPosition, lookVec); 58 | BoundingBox box = BoundingBox(vec3(0.), vec3(1.)); 59 | 60 | float tnear, tfar; 61 | IntersectBox(eye, box, tnear, tfar); 62 | if (tnear < 0.15) tnear = 0.15; 63 | if (tnear > tfar) discard; 64 | 65 | vec3 rayStart = (eye.Origin + eye.Dir * tnear) * (maxv - minv) + minv; //vol_d/vol_d_pot; 66 | vec3 rayStop = (eye.Origin + eye.Dir * tfar) * (maxv - minv) + minv; //vol_d/vol_d_pot; 67 | 68 | vec3 dir = rayStop - rayStart; // starting position of the ray 69 | 70 | vec = rayStart; 71 | float dl = length(dir); 72 | if (dl == clamp(dl, 0., vol_l)) 73 | { 74 | int steps = int(floor(length(vold * dir) * quality)); 75 | vec3 delta_dir = dir / float(steps); 76 | vec4 color_sample; 77 | float aScale = density / quality; 78 | 79 | float random = fract(sin(gl_FragCoord.x * 12.9898 + gl_FragCoord.y * 78.233) * 43758.5453); 80 | vec += delta_dir * random; 81 | 82 | //raycast 83 | for (int i = 0; i < steps; i++) 84 | { 85 | vec3 vecz = vec + zOffsetVec; 86 | if (vecz.z > maxv.z) 87 | { 88 | vecz.z -= maxv.z; 89 | } 90 | 91 | color_sample = texture(volume_tex, vecz); 92 | if (color_sample.a > threshold) 93 | { 94 | float oneMinusAlpha = 1. - col_acc.a; 95 | color_sample.a *= aScale; 96 | col_acc.rgb = mix(col_acc.rgb, color_sample.rgb * color_sample.a, oneMinusAlpha); 97 | col_acc.a += color_sample.a * oneMinusAlpha; 98 | col_acc.rgb /= col_acc.a; 99 | if (col_acc.a >= 1.0) 100 | { 101 | break; // terminate if opacity > 1 102 | } 103 | } 104 | vec += delta_dir; 105 | } 106 | } 107 | 108 | out_color = col_acc; 109 | } -------------------------------------------------------------------------------- /data/ofxVolumetrics/shaders/gl3/raycast.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 position; 4 | 5 | out vec3 v_texcoord; 6 | out vec3 v_cameraPosition; 7 | 8 | uniform mat4 modelViewProjectionMatrix; 9 | uniform mat4 modelViewMatrixInverse; 10 | 11 | void main() 12 | { 13 | gl_Position = modelViewProjectionMatrix * position; 14 | 15 | // as our vertex coordinates are normalized (0..1) 16 | // we can reuse them as 3d texture coordinates 17 | v_texcoord = position.xyz; 18 | 19 | v_cameraPosition = (modelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0)).xyz; 20 | } -------------------------------------------------------------------------------- /ofxVolumetricsExample/addons.make: -------------------------------------------------------------------------------- 1 | ofxVolumetrics 2 | -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/background.png -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit001.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit001.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit002.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit002.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit003.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit003.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit004.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit004.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit005.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit005.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit006.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit006.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit007.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit007.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit008.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit008.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit009.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit009.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit010.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit010.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit011.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit011.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit012.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit012.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit013.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit013.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit014.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit014.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit015.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit015.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit016.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit016.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit017.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit017.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit018.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit018.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit019.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit019.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit020.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit020.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit021.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit021.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit022.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit022.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit023.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit023.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit024.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit024.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit025.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit025.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit026.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit026.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit027.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit027.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit028.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit028.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit029.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit029.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit030.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit030.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit031.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit031.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit032.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit032.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit033.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit033.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit034.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit034.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit035.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit035.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit036.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit036.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit037.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit037.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit038.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit038.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit039.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit039.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit040.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit040.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit041.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit041.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit042.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit042.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit043.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit043.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit044.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit044.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit045.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit045.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit046.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit046.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit047.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit047.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit048.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit048.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit049.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit049.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit050.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit050.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit051.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit051.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit052.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit052.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit053.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit053.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit054.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit054.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit055.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit055.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit056.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit056.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit057.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit057.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit058.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit058.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit059.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit059.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit060.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit060.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit061.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit061.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit062.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit062.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit063.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit063.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit064.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit064.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit065.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit065.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit066.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit066.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit067.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit067.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit068.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit068.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit069.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit069.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit070.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit070.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit071.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit071.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit072.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit072.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit073.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit073.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit074.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit074.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit075.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit075.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit076.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit076.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit077.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit077.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit078.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit078.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit079.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit079.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit080.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit080.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit081.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit081.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit082.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit082.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit083.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit083.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit084.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit084.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit085.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit085.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit086.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit086.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit087.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit087.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit088.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit088.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit089.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit089.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit090.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit090.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit091.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit091.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit092.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit092.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit093.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit093.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit094.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit094.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit095.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit095.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit096.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit096.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit097.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit097.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit098.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit098.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit099.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timscaffidi/ofxVolumetrics/4013293b0953d93cd391955b6d9b8306f0540e99/ofxVolumetricsExample/bin/data/volumes/head/cthead-8bit099.tif -------------------------------------------------------------------------------- /ofxVolumetricsExample/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | 4 | int main() { 5 | ofGLWindowSettings settings; 6 | settings.setGLVersion(3, 2); 7 | settings.setSize(800, 600); 8 | ofCreateWindow(settings); 9 | ofRunApp(new ofApp()); 10 | } 11 | -------------------------------------------------------------------------------- /ofxVolumetricsExample/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | 3 | 4 | void ofApp::setup() 5 | { 6 | ofSetFrameRate(60); 7 | ofSetLogLevel(OF_LOG_VERBOSE); 8 | background.allocate(1024,768,OF_IMAGE_COLOR); 9 | background.load("background.png"); 10 | ofEnableBlendMode(OF_BLENDMODE_ALPHA); 11 | 12 | imageSequence.init("volumes/head/cthead-8bit",3,".tif", 1); 13 | volWidth = imageSequence.getWidth(); 14 | volHeight = imageSequence.getHeight(); 15 | volDepth = imageSequence.getSequenceLength(); 16 | 17 | cout << "setting up volume data buffer at " << volWidth << "x" << volHeight << "x" << volDepth <<"\n"; 18 | 19 | volumeData = new unsigned char[volWidth*volHeight*volDepth*4]; 20 | 21 | for(int z=0; z 0 ? curFrame - 1 : 0; 44 | return worked; 45 | }; 46 | 47 | bool loadFrame(int n) { 48 | curFrame = startFrame + n; 49 | bool worked = load(generateFullFilename()); 50 | if (worked) 51 | curFrame++; 52 | return worked; 53 | }; 54 | 55 | int getCurrentFrameNumber() { return curFrame - startFrame; } 56 | void setCurrentFrameNumber(int i) { curFrame = startFrame + i; } 57 | int getSequenceLength() { return totalFrames; } 58 | bool isInitialized() { return initialized; } 59 | 60 | string generateFullFilename() { 61 | std::ostringstream ss; 62 | ss << std::setw(numDigits) << std::setfill('0') << curFrame; 63 | std::string result = ss.str(); 64 | if (result.length() > numDigits) { 65 | result.erase(0, result.length() - numDigits); 66 | } 67 | return fPrefix + ss.str() + fExt; 68 | }; 69 | 70 | private: 71 | bool initialized; 72 | int curFrame, startFrame; 73 | string fPrefix, fExt; 74 | int numDigits; 75 | int totalFrames; 76 | }; 77 | -------------------------------------------------------------------------------- /src/ofxTexture3d.cpp: -------------------------------------------------------------------------------- 1 | #include "ofxTexture3d.h" 2 | #include "ofTexture.cpp" 3 | 4 | ofxTexture3d::ofxTexture3d() { 5 | //ctor 6 | } 7 | 8 | ofxTexture3d::~ofxTexture3d() { 9 | release(texData.textureID); 10 | } 11 | 12 | void ofxTexture3d::allocate(int w, int h, int d, int internalGlDataType) { 13 | texData.tex_w = w; 14 | texData.tex_h = h; 15 | texData.tex_d = d; 16 | texData.tex_t = w; 17 | texData.tex_u = h; 18 | texData.tex_v = d; 19 | texData.textureTarget = GL_TEXTURE_3D; 20 | 21 | texData.glTypeInternal = internalGlDataType; 22 | texData.glInternalFormat = internalGlDataType; 23 | // get the glType (format) and pixelType (type) corresponding to the glTypeInteral (internalFormat) 24 | texData.glType = ofGetGLFormatFromInternal(texData.glTypeInternal); 25 | texData.pixelType = ofGetGlTypeFromInternal(texData.glTypeInternal); 26 | // attempt to free the previous bound texture, if we can: 27 | clear(); 28 | 29 | glGenTextures(1, (GLuint*)&texData.textureID); 30 | retain(texData.textureID); 31 | glEnable(texData.textureTarget); 32 | glBindTexture(texData.textureTarget, (GLuint)texData.textureID); 33 | 34 | glTexImage3D(texData.textureTarget, 0, texData.glTypeInternal, (GLint)texData.tex_w, (GLint)texData.tex_h, (GLint)texData.tex_d, 0, texData.glType, texData.pixelType, 0); 35 | 36 | glTexParameteri(texData.textureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 37 | glTexParameteri(texData.textureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 38 | glTexParameteri(texData.textureTarget, GL_TEXTURE_WRAP_S, GL_REPEAT); 39 | glTexParameteri(texData.textureTarget, GL_TEXTURE_WRAP_T, GL_REPEAT); 40 | glTexParameteri(texData.textureTarget, GL_TEXTURE_WRAP_R, GL_REPEAT); 41 | 42 | //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 43 | 44 | glDisable(texData.textureTarget); 45 | 46 | texData.width = w; 47 | texData.height = h; 48 | texData.depth = d; 49 | texData.bFlipTexture = false; 50 | texData.bAllocated = true; 51 | } 52 | 53 | void ofxTexture3d::loadData(unsigned char* data, int w, int h, int d, int xOffset, int yOffset, int zOffset, int glFormat) { 54 | loadData((void*)data, w, h, d, xOffset, yOffset, zOffset, glFormat); 55 | } 56 | void ofxTexture3d::loadData(float* data, int w, int h, int d, int xOffset, int yOffset, int zOffset, int glFormat) { 57 | loadData((void*)data, w, h, d, xOffset, yOffset, zOffset, glFormat); 58 | } 59 | void ofxTexture3d::loadData(unsigned short* data, int w, int h, int d, int xOffset, int yOffset, int zOffset, int glFormat) { 60 | loadData((void*)data, w, h, d, xOffset, yOffset, zOffset, glFormat); 61 | } 62 | void ofxTexture3d::loadData(ofPixels& pix, int d, int xOffset, int yOffset, int zOffset) { 63 | loadData(pix.getData(), pix.getWidth(), pix.getHeight(), d, xOffset, yOffset, zOffset, ofGetGlFormat(pix)); 64 | } 65 | void ofxTexture3d::loadData(ofShortPixels& pix, int d, int xOffset, int yOffset, int zOffset) { 66 | loadData(pix.getData(), pix.getWidth(), pix.getHeight(), d, xOffset, yOffset, zOffset, ofGetGlFormat(pix)); 67 | } 68 | void ofxTexture3d::loadData(ofFloatPixels& pix, int d, int xOffset, int yOffset, int zOffset) { 69 | loadData(pix.getData(), pix.getWidth(), pix.getHeight(), d, xOffset, yOffset, zOffset, ofGetGlFormat(pix)); 70 | } 71 | 72 | void ofxTexture3d::loadData(void* data, int w, int h, int d, int xOffset, int yOffset, int zOffset, int glFormat) { 73 | if (glFormat != texData.glType) { 74 | ofLogError() << "ofxTexture3d::loadData() failed to upload format " << ofGetGlInternalFormatName(glFormat) << " data to " << ofGetGlInternalFormatName(texData.glType) << " texture" << endl; 75 | return; 76 | } 77 | 78 | if (w > texData.tex_w || h > texData.tex_h || d > texData.tex_d) { 79 | ofLogError() << "ofxTexture3d::loadData() failed to upload " << w << "x" << h << "x" << d << " data to " << texData.tex_w << "x" << texData.tex_h << "x" << texData.tex_d << " texture"; 80 | return; 81 | } 82 | 83 | ofSetPixelStoreiAlignment(GL_UNPACK_ALIGNMENT, w, 1, ofGetNumChannelsFromGLFormat(glFormat)); 84 | glEnable(texData.textureTarget); 85 | glBindTexture(texData.textureTarget, (GLuint)texData.textureID); 86 | glTexSubImage3D(texData.textureTarget, 0, xOffset, yOffset, zOffset, w, h, d, texData.glType, texData.pixelType, data); 87 | glDisable(texData.textureTarget); 88 | 89 | } 90 | 91 | void ofxTexture3d::clear() { 92 | release(texData.textureID); 93 | texData.textureID = 0; 94 | texData.bAllocated = false; 95 | } 96 | 97 | void ofxTexture3d::setTextureMinMagFilter(GLint filterMode) 98 | { 99 | if (filterMode != GL_NEAREST && filterMode != GL_LINEAR) return; 100 | 101 | bind(); 102 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, filterMode); 103 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, filterMode); 104 | unbind(); 105 | } 106 | 107 | void ofxTexture3d::bind() { 108 | //we could check if it has been allocated - but we don't do that in draw() 109 | glEnable(texData.textureTarget); 110 | glBindTexture(texData.textureTarget, (GLuint)texData.textureID); 111 | } 112 | 113 | void ofxTexture3d::bindAsImage(GLuint unit, GLenum access, GLint level, GLboolean layered, GLint layer) { 114 | glBindImageTexture(unit, texData.textureID, level, layered, layer, access, texData.glInternalFormat); 115 | } 116 | 117 | //---------------------------------------------------------- 118 | void ofxTexture3d::unbind() { 119 | glBindTexture(texData.textureTarget, 0); 120 | glDisable(texData.textureTarget); 121 | } 122 | 123 | ofxTextureData3d ofxTexture3d::getTextureData() { 124 | if (!texData.bAllocated) { 125 | ofLog(OF_LOG_ERROR, "getTextureData() - texture has not been allocated"); 126 | } 127 | 128 | return texData; 129 | } 130 | -------------------------------------------------------------------------------- /src/ofxTexture3d.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ofTexture.h" 3 | 4 | class ofxTextureData3d : public ofTextureData { 5 | public: 6 | ofxTextureData3d() { 7 | textureID = 0; 8 | 9 | glTypeInternal = GL_RGB8; 10 | textureTarget = GL_TEXTURE_3D; 11 | 12 | glType = GL_RGB; 13 | pixelType = GL_UNSIGNED_BYTE; 14 | 15 | tex_t = 0; 16 | tex_u = 0; 17 | tex_v = 0; 18 | tex_w = 0; 19 | tex_h = 0; 20 | tex_d = 0; 21 | width = 0; 22 | height = 0; 23 | depth = 0; 24 | 25 | bFlipTexture = false; 26 | compressionType = OF_COMPRESS_NONE; 27 | bAllocated = false; 28 | } 29 | 30 | float tex_v; 31 | float tex_d; 32 | float depth; 33 | int glType, pixelType; 34 | int glTypeInternal; 35 | }; 36 | 37 | class ofxTexture3d { 38 | public: 39 | ofxTexture3d(); 40 | virtual ~ofxTexture3d(); 41 | void allocate(int w, int h, int d, int internalGlDataType); 42 | void loadData(unsigned char* data, int w, int h, int d, int xOffset, int yOffset, int zOffset, int glFormat); 43 | void loadData(float* data, int w, int h, int d, int xOffset, int yOffset, int zOffset, int glFormat); 44 | void loadData(unsigned short* data, int w, int h, int d, int xOffset, int yOffset, int zOffset, int glFormat); 45 | void loadData(ofPixels& pix, int d, int xOffset, int yOffset, int zOffset); 46 | void loadData(ofShortPixels& pix, int d, int xOffset, int yOffset, int zOffset); 47 | void loadData(ofFloatPixels& pix, int d, int xOffset, int yOffset, int zOffset); 48 | void bind(); 49 | void bindAsImage(GLuint unit, GLenum access, GLint level = 0, GLboolean layered = GL_TRUE, GLint layer = 0); 50 | void unbind(); 51 | void clear(); 52 | void setTextureMinMagFilter(GLint filterMode); 53 | ofxTextureData3d getTextureData(); 54 | protected: 55 | void loadData(void* data, int w, int h, int d, int xOffset, int yOffset, int zOffset, int glFormat); 56 | private: 57 | ofxTextureData3d texData; 58 | }; 59 | -------------------------------------------------------------------------------- /src/ofxVolumetrics.cpp: -------------------------------------------------------------------------------- 1 | #include "ofxVolumetrics.h" 2 | #include "ofMain.h" 3 | 4 | using namespace glm; 5 | 6 | ofxVolumetrics::~ofxVolumetrics() { 7 | destroy(); 8 | } 9 | 10 | ofxVolumetrics::ofxVolumetrics() { 11 | quality = vec3(1.0); 12 | threshold = 1.0 / 255.0; 13 | density = 1.0; 14 | volWidth = renderWidth = 0; 15 | volHeight = renderHeight = 0; 16 | volDepth = 0; 17 | bIsInitialized = false; 18 | bDrawDebugVolume = false; 19 | 20 | vector vertices { 21 | // front side 22 | vec3(1.0, 1.0, 1.0), 23 | vec3(0.0, 1.0, 1.0), 24 | vec3(1.0, 0.0, 1.0), 25 | vec3(0.0, 0.0, 1.0), 26 | // right side 27 | vec3(1.0, 1.0, 0.0), 28 | vec3(1.0, 1.0, 1.0), 29 | vec3(1.0, 0.0, 0.0), 30 | vec3(1.0, 0.0, 1.0), 31 | // top side 32 | vec3(0.0, 1.0, 0.0), 33 | vec3(0.0, 1.0, 1.0), 34 | vec3(1.0, 1.0, 0.0), 35 | vec3(1.0, 1.0, 1.0), 36 | // left side 37 | vec3(0.0, 1.0, 1.0), 38 | vec3(0.0, 1.0, 0.0), 39 | vec3(0.0, 0.0, 1.0), 40 | vec3(0.0, 0.0, 0.0), 41 | // bottom side 42 | vec3(1.0, 0.0, 1.0), 43 | vec3(0.0, 0.0, 1.0), 44 | vec3(1.0, 0.0, 0.0), 45 | vec3(0.0, 0.0, 0.0), 46 | // back side 47 | vec3(0.0, 1.0, 0.0), 48 | vec3(1.0, 1.0, 0.0), 49 | vec3(0.0, 0.0, 0.0), 50 | vec3(1.0, 0.0, 0.0) 51 | }; 52 | vector indices { 53 | // front side 54 | 0, 2, 1, 1, 2, 3, 55 | // right side 56 | 4, 6, 5, 5, 6, 7, 57 | // top side 58 | 8, 10, 9, 9, 10, 11, 59 | // left side 60 | 12, 14, 13, 13, 14, 15, 61 | // bottom side 62 | 16, 18, 17, 17, 18, 19, 63 | // back side 64 | 20, 22, 21, 21, 22, 23 65 | }; 66 | volumeMesh.addVertices(vertices); 67 | volumeMesh.addIndices(indices); 68 | } 69 | 70 | void ofxVolumetrics::setup(int w, int h, int d, vec3 voxelSize, bool usePowerOfTwoTexSize) { 71 | string shadersPath = "ofxVolumetrics/shaders/"; 72 | shadersPath += ofIsGLProgrammableRenderer() ? "gl3/" : "gl2/"; 73 | volumeShader.unload(); 74 | volumeShader.load(shadersPath + "raycast.vert", shadersPath + "raycast.frag"); 75 | 76 | bIsPowerOfTwo = usePowerOfTwoTexSize; 77 | 78 | volWidthPOT = volWidth = renderWidth = w; 79 | volHeightPOT = volHeight = renderHeight = h; 80 | volDepthPOT = volDepth = d; 81 | 82 | if (bIsPowerOfTwo) { 83 | volWidthPOT = ofNextPow2(w); 84 | volHeightPOT = ofNextPow2(h); 85 | volDepthPOT = ofNextPow2(d); 86 | 87 | ofLogVerbose() << "ofxVolumetrics::setup(): Using power of two texture size. Requested: " << w << "x" << h << "x" << d << ". Actual: " << volWidthPOT << "x" << volHeightPOT << "x" << volDepthPOT << ".\n"; 88 | } 89 | 90 | fboRender.allocate(w, h, GL_RGBA8); 91 | volumeTexture.allocate(volWidthPOT, volHeightPOT, volDepthPOT, GL_RGBA8); 92 | if (bIsPowerOfTwo) { 93 | // if using cropped power of two, blank out the extra memory 94 | unsigned char* d; 95 | d = new unsigned char[volWidthPOT * volHeightPOT * volDepthPOT * 4]; 96 | memset(d, 0, volWidthPOT * volHeightPOT * volDepthPOT * 4); 97 | volumeTexture.loadData(d, volWidthPOT, volHeightPOT, volDepthPOT, 0, 0, 0, GL_RGBA); 98 | } 99 | voxelRatio = voxelSize; 100 | 101 | bIsInitialized = true; 102 | } 103 | 104 | void ofxVolumetrics::destroy() { 105 | volumeShader.unload(); 106 | volumeTexture.clear(); 107 | 108 | volWidth = renderWidth = 0; 109 | volHeight = renderHeight = 0; 110 | volDepth = 0; 111 | bIsInitialized = false; 112 | } 113 | 114 | void ofxVolumetrics::updateVolumeData(unsigned char* data, int w, int h, int d, int xOffset, int yOffset, int zOffset) { 115 | volumeTexture.loadData(data, w, h, d, xOffset, yOffset, zOffset, GL_RGBA); 116 | } 117 | 118 | void ofxVolumetrics::drawVolume(float x, float y, float z, float size, int zTexOffset) { 119 | vec3 volumeSize = voxelRatio * vec3(volWidth, volHeight, volDepth); 120 | float maxDim = glm::max(glm::max(volumeSize.x, volumeSize.y), volumeSize.z); 121 | volumeSize = volumeSize * size / maxDim; 122 | 123 | drawVolume(x, y, z, volumeSize.x, volumeSize.y, volumeSize.z, zTexOffset); 124 | } 125 | 126 | void ofxVolumetrics::drawVolume(float x, float y, float z, float w, float h, float d, int zTexOffset) { 127 | updateRenderDimentions(); 128 | 129 | // store current color 130 | GLint color[4]; 131 | glGetIntegerv(GL_CURRENT_COLOR, color); 132 | 133 | // store current cull mode 134 | GLint cull_mode; 135 | glGetIntegerv(GL_FRONT_FACE, &cull_mode); 136 | 137 | // set fbo cull mode 138 | mat4 matModelview = ofGetCurrentMatrix(OF_MATRIX_MODELVIEW); 139 | ofVec3f scale, t; ofQuaternion a, b; 140 | ofMatrix4x4(matModelview).decompose(t, a, scale, b); 141 | GLint cull_mode_fbo = (scale.x * scale.y * scale.z) > 0 ? GL_CCW : GL_CW; 142 | 143 | // raycasting pass 144 | fboRender.begin(OF_FBOMODE_NODEFAULTS); 145 | { 146 | // fix flipped y-axis 147 | ofSetMatrixMode(OF_MATRIX_PROJECTION); 148 | ofScale(1, -1, 1); 149 | ofSetMatrixMode(OF_MATRIX_MODELVIEW); 150 | ofScale(1, -1, 1); 151 | 152 | ofClear(0, 0); 153 | 154 | vec3 cubeSize(w, h, d); 155 | vec3 cubePos(x, y, z); 156 | ofTranslate(cubePos - cubeSize / 2.f); 157 | ofScale(cubeSize.x, cubeSize.y, cubeSize.z); 158 | 159 | volumeShader.begin(); 160 | volumeShader.setUniformTexture("volume_tex", GL_TEXTURE_3D, volumeTexture.getTextureData().textureID, 0); 161 | volumeShader.setUniform3f("vol_d", vec3(volWidth, volHeight, volDepth)); //dimensions of the volume texture 162 | volumeShader.setUniform3f("vol_d_pot", vec3(volWidthPOT, volHeightPOT, volDepthPOT)); //dimensions of the volume texture power of two 163 | volumeShader.setUniform2f("bg_d", vec2(renderWidth, renderHeight)); // dimensions of the background texture 164 | volumeShader.setUniform1f("zoffset", zTexOffset); // used for animation so that we dont have to upload the entire volume every time 165 | volumeShader.setUniform1f("quality", quality.z); // 0..1 166 | volumeShader.setUniform1f("density", density); // 0..1 167 | volumeShader.setUniform1f("threshold", threshold); 168 | if (ofIsGLProgrammableRenderer()) { 169 | volumeShader.setUniformMatrix4f("modelViewMatrixInverse", inverse(ofGetCurrentMatrix(OF_MATRIX_MODELVIEW))); 170 | } 171 | 172 | glFrontFace(cull_mode_fbo); 173 | glEnable(GL_CULL_FACE); 174 | glCullFace(GL_FRONT); 175 | volumeMesh.drawFaces(); 176 | glDisable(GL_CULL_FACE); 177 | glFrontFace(cull_mode); 178 | 179 | volumeShader.end(); 180 | 181 | if (bDrawDebugVolume) { 182 | glFrontFace(cull_mode_fbo); 183 | glEnable(GL_CULL_FACE); 184 | glCullFace(GL_FRONT); 185 | volumeMesh.drawWireframe(); 186 | glDisable(GL_CULL_FACE); 187 | glFrontFace(cull_mode); 188 | } 189 | } 190 | fboRender.end(); 191 | 192 | ofPushView(); 193 | 194 | glColor4iv(color); 195 | ofSetupScreenOrtho(); 196 | fboRender.draw(0, 0, ofGetWidth(), ofGetHeight()); 197 | 198 | ofPopView(); 199 | } 200 | 201 | void ofxVolumetrics::updateRenderDimentions() { 202 | if ((int)(ofGetWidth() * quality.x) != renderWidth) { 203 | renderWidth = ofGetWidth() * quality.x; 204 | renderHeight = ofGetHeight() * quality.x; 205 | fboRender.allocate(renderWidth, renderHeight, GL_RGBA); 206 | } 207 | } 208 | 209 | void ofxVolumetrics::setXyQuality(float q) { 210 | quality.x = MAX(q, 0.01); 211 | 212 | updateRenderDimentions(); 213 | } 214 | void ofxVolumetrics::setZQuality(float q) { 215 | quality.z = MAX(q, 0.01); 216 | } 217 | void ofxVolumetrics::setThreshold(float t) { 218 | threshold = ofClamp(t, 0.0, 1.0); 219 | } 220 | void ofxVolumetrics::setDensity(float d) { 221 | density = MAX(d, 0.0); 222 | } 223 | void ofxVolumetrics::setRenderSettings(float xyQuality, float zQuality, float dens, float thresh) { 224 | setXyQuality(xyQuality); 225 | setZQuality(zQuality); 226 | setDensity(dens); 227 | setThreshold(thresh); 228 | } 229 | 230 | void ofxVolumetrics::setVolumeTextureFilterMode(GLint filterMode) { 231 | volumeTexture.setTextureMinMagFilter(filterMode); 232 | } 233 | 234 | void ofxVolumetrics::setDrawDebugVolume(bool b) { 235 | bDrawDebugVolume = b; 236 | } 237 | 238 | bool ofxVolumetrics::isInitialized() { 239 | return bIsInitialized; 240 | } 241 | int ofxVolumetrics::getVolumeWidth() { 242 | return volWidth; 243 | } 244 | int ofxVolumetrics::getVolumeHeight() { 245 | return volHeight; 246 | } 247 | int ofxVolumetrics::getVolumeDepth() { 248 | return volDepth; 249 | } 250 | int ofxVolumetrics::getRenderWidth() { 251 | return renderWidth; 252 | } 253 | int ofxVolumetrics::getRenderHeight() { 254 | return renderHeight; 255 | } 256 | float ofxVolumetrics::getXyQuality() { 257 | return quality.x; 258 | } 259 | float ofxVolumetrics::getZQuality() { 260 | return quality.z; 261 | } 262 | float ofxVolumetrics::getThreshold() { 263 | return threshold; 264 | } 265 | float ofxVolumetrics::getDensity() { 266 | return density; 267 | } 268 | const ofFbo& ofxVolumetrics::getFbo() const { 269 | return fboRender; 270 | } 271 | -------------------------------------------------------------------------------- /src/ofxVolumetrics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | ofxVolumetrics - render volumetric data on the GPU 5 | 6 | Written by Timothy Scaffidi (http://timothyscaffidi.com) 7 | Volumetric rendering algorithm adapted from Peter Trier (http://www.daimi.au.dk/~trier/?page_id=98) 8 | 9 | */ 10 | 11 | #include "ofFbo.h" 12 | #include "ofShader.h" 13 | #include "ofxTexture3d.h" 14 | #include "ofxImageSequencePlayer.h" 15 | 16 | class ofxVolumetrics 17 | { 18 | public: 19 | 20 | ofxVolumetrics(); 21 | virtual ~ofxVolumetrics(); 22 | 23 | void setup(int w, int h, int d, glm::vec3 voxelSize, bool usePowerOfTwoTexSize = false); 24 | 25 | void destroy(); 26 | 27 | void updateVolumeData(unsigned char* data, int w, int h, int d, int xOffset, int yOffset, int zOffset); 28 | 29 | void drawVolume(float x, float y, float z, float size, int zTexOffset); 30 | void drawVolume(float x, float y, float z, float w, float h, float d, int zTexOffset); 31 | 32 | bool isInitialized(); 33 | int getVolumeWidth(); 34 | int getVolumeHeight(); 35 | int getVolumeDepth(); 36 | const ofFbo& getFbo() const; 37 | int getRenderWidth(); 38 | int getRenderHeight(); 39 | float getXyQuality(); 40 | float getZQuality(); 41 | float getThreshold(); 42 | float getDensity(); 43 | 44 | void setXyQuality(float q); 45 | void setZQuality(float q); 46 | void setThreshold(float t); 47 | void setDensity(float d); 48 | void setRenderSettings(float xyQuality, float zQuality, float dens, float thresh); 49 | void setVolumeTextureFilterMode(GLint filterMode); 50 | void setDrawDebugVolume(bool b); 51 | 52 | protected: 53 | 54 | private: 55 | 56 | void updateRenderDimentions(); 57 | 58 | ofFbo fboRender; 59 | ofShader volumeShader; 60 | ofxTexture3d volumeTexture; 61 | ofVboMesh volumeMesh; 62 | 63 | glm::vec3 voxelRatio; 64 | bool bIsInitialized; 65 | int volWidth, volHeight, volDepth; 66 | int volWidthPOT, volHeightPOT, volDepthPOT; 67 | bool bIsPowerOfTwo; 68 | glm::vec3 quality; 69 | float threshold; 70 | float density; 71 | int renderWidth, renderHeight; 72 | 73 | bool bDrawDebugVolume; 74 | }; 75 | --------------------------------------------------------------------------------