Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rystylee committed Aug 5, 2019
0 parents commit 8473e84
Show file tree
Hide file tree
Showing 45 changed files with 1,924 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
*bin/*.app
*.mp4
*imgui.ini
*.pt

libs/*

## mac
*config.make
*Makefile
*openFrameworks-Info.plist
*Project.xcconfig
*.xcodeproj

.DS_Store
*/.DS_Store

## windows
*.obj
*.vs
*.exe
*.ilk
*.lib
*.pdb
*.exp
*.iobj
*.ipdb
*.dll
*.sln
*.vcxproj*
*icon.rc
*obj

# Editor
.vscode/*

# Keep empty folder
!.gitkeep
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Ryosuke Nakajima

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ofxLibTorch

## Description
an openFrameworks wrapper for [LibTorch](https://pytorch.org/cppdocs/)

## Requirements
- openFramewrks v0.10.1
- LibTorch v1.1
- Windows10
- CUDA v10.0

## Licence
[MIT](https://github.com/rystylee/ofxLibTorch/blob/master/LICENSE)
127 changes: 127 additions & 0 deletions addon_config.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# All variables and this file are optional, if they are not present the PG and the
# makefiles will try to parse the correct values from the file system.
#
# Variables that specify exclusions can use % as a wildcard to specify that anything in
# that position will match. A partial path can also be specified to, for example, exclude
# a whole folder from the parsed paths from the file system
#
# Variables can be specified using = or +=
# = will clear the contents of that variable both specified from the file or the ones parsed
# from the file system
# += will add the values to the previous ones in the file or the ones parsed from the file
# system
#
# The PG can be used to detect errors in this file, just create a new project with this addon
# and the PG will write to the console the kind of error and in which line it is

meta:
ADDON_NAME = ofxLibTorch
ADDON_DESCRIPTION = Addon for LibTorch
ADDON_AUTHOR = @rystylee
ADDON_TAGS = "machine learning" "deep learning"
ADDON_URL = http://github.com/yournamehere/ofxAddonTemplate

common:
# dependencies with other addons, a list of them separated by spaces
# or use += in several lines
# ADDON_DEPENDENCIES =

# include search paths, this will be usually parsed from the file system
# but if the addon or addon libraries need special search paths they can be
# specified here separated by spaces or one per line using +=
# ADDON_INCLUDES =

# any special flag that should be passed to the compiler when using this
# addon
# ADDON_CFLAGS =

# any special flag that should be passed to the compiler for c++ files when
# using this addon
# ADDON_CPPFLAGS =

# any special flag that should be passed to the linker when using this
# addon, also used for system libraries with -lname
# ADDON_LDFLAGS =

# source files, these will be usually parsed from the file system looking
# in the src folders in libs and the root of the addon. if your addon needs
# to include files in different places or a different set of files per platform
# they can be specified here
# ADDON_SOURCES =

# source files that will be included as C files explicitly
# ADDON_C_SOURCES =

# source files that will be included as header files explicitly
# ADDON_HEADER_SOURCES =

# source files that will be included as c++ files explicitly
# ADDON_CPP_SOURCES =

# source files that will be included as objective c files explicitly
# ADDON_OBJC_SOURCES =

# derines that will be passed to the compiler when including this addon
# ADDON_DEFINES

# some addons need resources to be copied to the bin/data folder of the project
# specify here any files that need to be copied, you can use wildcards like * and ?
# ADDON_DATA =

# when parsing the file system looking for libraries exclude this for all or
# a specific platform
# ADDON_LIBS_EXCLUDE =

# binary libraries, these will be usually parsed from the file system but some
# libraries need to passed to the linker in a specific order/
#
# For example in the ofxOpenCV addon we do something like this:
#
# ADDON_LIBS =
# ADDON_LIBS += libs/opencv/lib/linuxarmv6l/libopencv_legacy.a
# ADDON_LIBS += libs/opencv/lib/linuxarmv6l/libopencv_calib3d.a
# ...


linux64:
# linux only, any library that should be included in the project using
# pkg-config
# ADDON_PKG_CONFIG_LIBRARIES =
vs:
# After compiling copy the following dynamic libraries to the executable directory
# only windows visual studio
# ADDON_DLLS_TO_COPY =

ADDON_INCLUDES =
ADDON_INCLUDES += "src"
ADDON_INCLUDES += "libs/libtorch-v.1.1.0-windows-cu100-release/include"
ADDON_INCLUDES += "libs/libtorch-v.1.1.0-windows-cu100-release/include/torch/csrc/api/include"
ADDON_INCLUDES += "C:/Program Files/NVIDIA Corporation/NvToolsExt/include"
ADDON_INCLUDES += "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/include"

ADDON_INCLUDES += "libs/opencv-4.1.0-vc14_vc15/build/include"

ADDON_LIBS =
ADDON_LIBS += "libs/libtorch-v.1.1.0-windows-cu100-release/lib/torch.lib"
ADDON_LIBS += "libs/libtorch-v.1.1.0-windows-cu100-release/lib/c10.lib"
ADDON_LIBS += "libs/libtorch-v.1.1.0-windows-cu100-release/lib/c10_cuda.lib"
ADDON_LIBS += "libs/libtorch-v.1.1.0-windows-cu100-release/lib/caffe2_gpu.lib"
ADDON_LIBS += "libs/libtorch-v.1.1.0-windows-cu100-release/lib/caffe2.lib"
ADDON_LIBS += "C:/Program Files/NVIDIA Corporation/NvToolsExt/lib/x64/nvToolsExt64_1.lib"
ADDON_LIBS += "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64/cudart.lib"
ADDON_LIBS += "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64/cufft.lib"
ADDON_LIBS += "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64/curand.lib"
ADDON_LIBS += "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64/cudnn.lib"
ADDON_LIBS += "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64/cublas.lib"

ADDON_LIBS += "libs/opencv-4.1.0-vc14_vc15/build/x64/vc15/lib/opencv_world410.lib"

linuxarmv6l:
linuxarmv7l:
android/armeabi:
android/armeabi-v7a:
osx:
# osx/iOS only, any framework that should be included in the project
# ADDON_FRAMEWORKS =
ios:
tvos:
2 changes: 2 additions & 0 deletions examples/AdaIN/addons.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ofxImGui
ofxLibTorch
Empty file.
135 changes: 135 additions & 0 deletions examples/AdaIN/bin/data/shaders/content.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#version 450 core
precision mediump float;

in vec4 vPosition;
in vec2 vTexCoord;

uniform vec2 uResolution;
uniform float uTime;

out vec4 fragColor;

/* ~~~ Util: Ashima Webgl Noise ~~~ */

// Description : Array and textureless GLSL 2D simplex noise function.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
//

vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec3 permute(vec3 x) {
return mod289(((x*34.0)+1.0)*x);
}

float snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);

// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;

// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));

vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;

// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)

vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;

// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );

// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}

/* ~~~ End Webgl Noise ~~~ */


#define NB_OCTAVES 6
#define LACUNARITY 2.0
#define GAIN 0.5

float fbm(in vec2 p) {
float total = 0.0,
frequency = 1.0,
amplitude = 1.0;

for (int i = 0; i < NB_OCTAVES; i++) {
total += snoise(p * frequency) * amplitude;
frequency *= LACUNARITY;
amplitude *= GAIN;
}
return total;
}

float t;
float c1, c2, s1, s2;

float pattern(in vec2 p, out float c) {
float t = uTime;
vec2 q = vec2( fbm( p + vec2(0.0, 0.0) ),
fbm( p + vec2(c2*.1, t*.02)) );

c = fbm( p + 2.0*q + vec2(c1+c2,-t*.01));
return fbm( p + 2.0*q );
}


void main()
{
vec2 uv = vPosition.xy / uResolution.xy;
t = uTime;

c1 = 0.1 + cos(t * 0.01) * 0.9; c2 = 0.4 + cos(t * 0.06) * 0.4;
s1 = sin(t * 0.03); s2 = sin(t*0.3);

vec2 p = vec2(uv.x + c1 * 0.4 + c2 * 0.6, uv.y * 0.3 );

p.x *= 0.4+ c2 * 0.4;

float c;
vec3 col = vec3(pattern(p, c));
col.r = .6+mix(col.x, c, .2);
col.b = 0.2+mix(col.x, c, .5)*.1;

fragColor = vec4(col,1.0);
}
26 changes: 26 additions & 0 deletions examples/AdaIN/bin/data/shaders/pass.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#version 450 core

// -----------------------------
// oF default
// -----------------------------
layout (location = 0) in vec4 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec4 normal;
layout (location = 3) in vec2 texcoord;

out vec4 vPosition;
out vec4 vColor;
out vec4 vNormal;
out vec2 vTexCoord;

uniform mat4 modelViewProjectionMatrix;
uniform mat4 modelViewMatrix;

void main()
{
vPosition = position;
vColor = color;
vNormal = normal;
vTexCoord = texcoord;
gl_Position = modelViewProjectionMatrix * position;
}
Loading

0 comments on commit 8473e84

Please sign in to comment.