diff --git a/3rdparty/VSML/vsml.cpp b/3rdparty/VSML/vsml.cpp old mode 100755 new mode 100644 diff --git a/3rdparty/VSML/vsml.h b/3rdparty/VSML/vsml.h old mode 100755 new mode 100644 diff --git a/3rdparty/fftw/fftw3.h b/3rdparty/fftw/fftw3.h deleted file mode 100755 index 5523a3d..0000000 --- a/3rdparty/fftw/fftw3.h +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright (c) 2003, 2007-11 Matteo Frigo - * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology - * - * The following statement of license applies *only* to this header file, - * and *not* to the other files distributed with FFTW or derived therefrom: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/***************************** NOTE TO USERS ********************************* - * - * THIS IS A HEADER FILE, NOT A MANUAL - * - * If you want to know how to use FFTW, please read the manual, - * online at http://www.fftw.org/doc/ and also included with FFTW. - * For a quick start, see the manual's tutorial section. - * - * (Reading header files to learn how to use a library is a habit - * stemming from code lacking a proper manual. Arguably, it's a - * *bad* habit in most cases, because header files can contain - * interfaces that are not part of the public, stable API.) - * - ****************************************************************************/ - -#ifndef FFTW3_H -#define FFTW3_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/* If is included, use the C99 complex type. Otherwise - define a type bit-compatible with C99 complex */ -#if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) -# define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C -#else -# define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2] -#endif - -#define FFTW_CONCAT(prefix, name) prefix ## name -#define FFTW_MANGLE_DOUBLE(name) FFTW_CONCAT(fftw_, name) -#define FFTW_MANGLE_FLOAT(name) FFTW_CONCAT(fftwf_, name) -#define FFTW_MANGLE_LONG_DOUBLE(name) FFTW_CONCAT(fftwl_, name) -#define FFTW_MANGLE_QUAD(name) FFTW_CONCAT(fftwq_, name) - -/* IMPORTANT: for Windows compilers, you should add a line -*/ -#define FFTW_DLL -/* - here and in kernel/ifftw.h if you are compiling/using FFTW as a - DLL, in order to do the proper importing/exporting, or - alternatively compile with -DFFTW_DLL or the equivalent - command-line flag. This is not necessary under MinGW/Cygwin, where - libtool does the imports/exports automatically. */ -#if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__)) - /* annoying Windows syntax for shared-library declarations */ -# if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */ -# define FFTW_EXTERN extern __declspec(dllexport) -# else /* user is calling FFTW; import symbol */ -# define FFTW_EXTERN extern __declspec(dllimport) -# endif -#else -# define FFTW_EXTERN extern -#endif - -enum fftw_r2r_kind_do_not_use_me { - FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2, - FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6, - FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10 -}; - -struct fftw_iodim_do_not_use_me { - int n; /* dimension size */ - int is; /* input stride */ - int os; /* output stride */ -}; - -#include /* for ptrdiff_t */ -struct fftw_iodim64_do_not_use_me { - ptrdiff_t n; /* dimension size */ - ptrdiff_t is; /* input stride */ - ptrdiff_t os; /* output stride */ -}; - -typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *); -typedef int (*fftw_read_char_func_do_not_use_me)(void *); - -/* - huge second-order macro that defines prototypes for all API - functions. We expand this macro for each supported precision - - X: name-mangling macro - R: real data type - C: complex data type -*/ - -#define FFTW_DEFINE_API(X, R, C) \ - \ -FFTW_DEFINE_COMPLEX(R, C); \ - \ -typedef struct X(plan_s) *X(plan); \ - \ -typedef struct fftw_iodim_do_not_use_me X(iodim); \ -typedef struct fftw_iodim64_do_not_use_me X(iodim64); \ - \ -typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \ - \ -typedef fftw_write_char_func_do_not_use_me X(write_char_func); \ -typedef fftw_read_char_func_do_not_use_me X(read_char_func); \ - \ -FFTW_EXTERN void X(execute)(const X(plan) p); \ - \ -FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \ - C *in, C *out, int sign, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \ - C *in, C *out, int sign, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \ - C *in, C *out, int sign, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \ - int howmany, \ - C *in, const int *inembed, \ - int istride, int idist, \ - C *out, const int *onembed, \ - int ostride, int odist, \ - int sign, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - C *in, C *out, \ - int sign, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *ri, R *ii, R *ro, R *io, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \ - const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - C *in, C *out, \ - int sign, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \ - const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *ri, R *ii, R *ro, R *io, \ - unsigned flags); \ - \ -FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \ -FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \ - R *ro, R *io); \ - \ -FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \ - int howmany, \ - R *in, const int *inembed, \ - int istride, int idist, \ - C *out, const int *onembed, \ - int ostride, int odist, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \ - R *in, C *out, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \ - R *in, C *out, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \ - int n2, \ - R *in, C *out, unsigned flags); \ - \ - \ -FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \ - int howmany, \ - C *in, const int *inembed, \ - int istride, int idist, \ - R *out, const int *onembed, \ - int ostride, int odist, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \ - C *in, R *out, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \ - C *in, R *out, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \ - int n2, \ - C *in, R *out, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *in, C *out, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - C *in, R *out, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \ - int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *in, R *ro, R *io, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \ - int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *ri, R *ii, R *out, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \ - const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *in, C *out, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \ - const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - C *in, R *out, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \ - int rank, const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *in, R *ro, R *io, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \ - int rank, const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *ri, R *ii, R *out, \ - unsigned flags); \ - \ -FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \ -FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \ - \ -FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \ - R *in, R *ro, R *io); \ -FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \ - R *ri, R *ii, R *out); \ - \ -FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \ - int howmany, \ - R *in, const int *inembed, \ - int istride, int idist, \ - R *out, const int *onembed, \ - int ostride, int odist, \ - const X(r2r_kind) *kind, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \ - const X(r2r_kind) *kind, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \ - X(r2r_kind) kind, unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \ - X(r2r_kind) kind0, X(r2r_kind) kind1, \ - unsigned flags); \ -FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \ - R *in, R *out, X(r2r_kind) kind0, \ - X(r2r_kind) kind1, X(r2r_kind) kind2, \ - unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \ - int howmany_rank, \ - const X(iodim) *howmany_dims, \ - R *in, R *out, \ - const X(r2r_kind) *kind, unsigned flags); \ - \ -FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \ - int howmany_rank, \ - const X(iodim64) *howmany_dims, \ - R *in, R *out, \ - const X(r2r_kind) *kind, unsigned flags); \ - \ -FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \ - \ -FFTW_EXTERN void X(destroy_plan)(X(plan) p); \ -FFTW_EXTERN void X(forget_wisdom)(void); \ -FFTW_EXTERN void X(cleanup)(void); \ - \ -FFTW_EXTERN void X(set_timelimit)(double t); \ - \ -FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \ -FFTW_EXTERN int X(init_threads)(void); \ -FFTW_EXTERN void X(cleanup_threads)(void); \ - \ -FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \ -FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \ -FFTW_EXTERN char *X(export_wisdom_to_string)(void); \ -FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \ - void *data); \ -FFTW_EXTERN int X(import_system_wisdom)(void); \ -FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \ -FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \ -FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \ -FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \ - \ -FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \ -FFTW_EXTERN void X(print_plan)(const X(plan) p); \ - \ -FFTW_EXTERN void *X(malloc)(size_t n); \ -FFTW_EXTERN R *X(alloc_real)(size_t n); \ -FFTW_EXTERN C *X(alloc_complex)(size_t n); \ -FFTW_EXTERN void X(free)(void *p); \ - \ -FFTW_EXTERN void X(flops)(const X(plan) p, \ - double *add, double *mul, double *fmas); \ -FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \ -FFTW_EXTERN double X(cost)(const X(plan) p); \ - \ -FFTW_EXTERN const char X(version)[]; \ -FFTW_EXTERN const char X(cc)[]; \ -FFTW_EXTERN const char X(codelet_optim)[]; - - -/* end of FFTW_DEFINE_API macro */ - -FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex) -FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex) -FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex) - -/* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64 - for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */ -#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \ - && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__)) -# if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) -/* note: __float128 is a typedef, which is not supported with the _Complex - keyword in gcc, so instead we use this ugly __attribute__ version. - However, we can't simply pass the __attribute__ version to - FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer - types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */ -# undef FFTW_DEFINE_COMPLEX -# define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C -# endif -FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex) -#endif - -#define FFTW_FORWARD (-1) -#define FFTW_BACKWARD (+1) - -#define FFTW_NO_TIMELIMIT (-1.0) - -/* documented flags */ -#define FFTW_MEASURE (0U) -#define FFTW_DESTROY_INPUT (1U << 0) -#define FFTW_UNALIGNED (1U << 1) -#define FFTW_CONSERVE_MEMORY (1U << 2) -#define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */ -#define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */ -#define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */ -#define FFTW_ESTIMATE (1U << 6) - -/* undocumented beyond-guru flags */ -#define FFTW_ESTIMATE_PATIENT (1U << 7) -#define FFTW_BELIEVE_PCOST (1U << 8) -#define FFTW_NO_DFT_R2HC (1U << 9) -#define FFTW_NO_NONTHREADED (1U << 10) -#define FFTW_NO_BUFFERING (1U << 11) -#define FFTW_NO_INDIRECT_OP (1U << 12) -#define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */ -#define FFTW_NO_RANK_SPLITS (1U << 14) -#define FFTW_NO_VRANK_SPLITS (1U << 15) -#define FFTW_NO_VRECURSE (1U << 16) -#define FFTW_NO_SIMD (1U << 17) -#define FFTW_NO_SLOW (1U << 18) -#define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19) -#define FFTW_ALLOW_PRUNING (1U << 20) -#define FFTW_WISDOM_ONLY (1U << 21) - -#ifdef __cplusplus -} /* extern "C" */ -#endif /* __cplusplus */ - -#endif /* FFTW3_H */ diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 index 32ebf47..20da917 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ ifeq ($(BUILD_TYPE), debug) CFLAGS = -Wall -g -std=c++0x else CFLAGS = -O3 -msse2 -ffast-math -funswitch-loops -funsafe-math-optimizations \ - -fsingle-precision-constant -funsafe-loop-optimizations -fgcse-sm -fgcse-las -fsee -std=c++0x + -fsingle-precision-constant -funsafe-loop-optimizations -fgcse-sm -fgcse-las -fsee -std=c++0x -static endif ifeq ($(OS),Windows_NT) - LDFLAGS = -L/usr/local/lib -lglew32 -lglu32 -lopengl32 -lgdi32 -L3rdparty/fftw -lfftw3f + LDFLAGS = -LC:/MinGW/msys/1.0/lib -lglew32 -lglu32 -lopengl32 -lgdi32 -LC:/MinGW/msys/1.0/local/lib -lfftw3f -lpthread -lIL else LDFLAGS = -lm -lX11 -lGL -lGLU endif @@ -20,7 +20,7 @@ endif SRCDIR := src VSMLDIR := 3rdparty/VSML -INCLUDES = -IC:/Qt/qtcreator-2.2.82/mingw/include -I$(VSMLDIR) +INCLUDES = -IC:/MinGW/msys/1.0/include -IC:/MinGW/msys/1.0/local/include -I$(VSMLDIR) OBJFILES := $(patsubst $(VSMLDIR)/%.cpp,$(VSMLDIR)/%.o,$(wildcard $(VSMLDIR)/*.cpp)) \ $(patsubst $(SRCDIR)/%.cpp,$(SRCDIR)/%.o,$(wildcard $(SRCDIR)/*.cpp)) COMPILE = $(CC) $(CFLAGS) $(INCLUDES) -c diff --git a/README b/README old mode 100755 new mode 100644 diff --git a/Rocky.config b/Rocky.config old mode 100755 new mode 100644 diff --git a/Rocky.creator b/Rocky.creator old mode 100755 new mode 100644 diff --git a/Rocky.files b/Rocky.files old mode 100755 new mode 100644 index c7b553e..5a0e76d --- a/Rocky.files +++ b/Rocky.files @@ -28,3 +28,5 @@ src/glfftwater.h src/glfftwater.cpp shaders/post0.glsl shaders/post1.glsl +src/gltextureloader.h +src/gltextureloader.cpp diff --git a/Rocky.includes b/Rocky.includes old mode 100755 new mode 100644 index 0d591da..5c81c4f --- a/Rocky.includes +++ b/Rocky.includes @@ -1,2 +1,4 @@ 3rdparty/VSML src +C:/MinGW/msys/1.0/include +C:/MinGW/msys/1.0/local/include diff --git a/shaders/default.glsl b/shaders/default.glsl old mode 100755 new mode 100644 diff --git a/shaders/icosohedron.glsl b/shaders/icosohedron.glsl old mode 100755 new mode 100644 diff --git a/shaders/normals.glsl b/shaders/normals.glsl old mode 100755 new mode 100644 index 5c551a2..a20ef14 --- a/shaders/normals.glsl +++ b/shaders/normals.glsl @@ -11,44 +11,78 @@ in vec3 in_TexCoord; out vec3 vTexCoord; void main() { vTexCoord = in_TexCoord; - gl_Position = vec4(in_Position, 1.0); + gl_Position = projMatrix*modelviewMatrix * vec4(in_Position, 1.0); } #endif #ifdef _FRAGMENT_ in vec3 vTexCoord; -out float out_Color0; -out float out_Color1; -out float out_Color2; -out float out_Color3; -out float out_Color4; -out float out_Color5; -out float out_Color6; -out float out_Color7; +out vec3 out_Color0; +out vec3 out_Color1; +out vec3 out_Color2; +out vec3 out_Color3; +out vec3 out_Color4; +out vec3 out_Color5; +out vec3 out_Color6; +out vec3 out_Color7; + +vec3 computeNormal(vec3 pos, float size) { + float delta =(1.0/size); + float ndelta = -delta; + float prec = (0.5 / size); + + float off0 = -delta; + float off1 = -delta; + float off2 = delta; + float off3 = delta; + + float l0 = 0.0; + float l1 = 0.0; + float l2 = 0.0; + float l3 = 0.0; + + // need to check deltas and sample from different layers if we run over + if(pos.x + off0 <= 0.0) { + l0 -= 1.0; + off0 = 1.0 - off0; + } + else if(pos.x + off0 >= 1.0) { + l0 += 1.0; + off0 = 1.0 - off0; + } + + vec3 tc0 = pos+vec3(0.0,off0,l0); + vec3 tc1 = pos+vec3(off1,0.0,l1); + vec3 tc2 = pos+vec3(off2,0.0,l2); + vec3 tc3 = pos+vec3(0.0,off3,l3); + + tc0.st = clamp(tc0.st, prec, 1.0-prec); + tc1.st = clamp(tc1.st, prec, 1.0-prec); + tc2.st = clamp(tc2.st, prec, 1.0-prec); + tc3.st = clamp(tc3.st, prec, 1.0-prec); + + float p0 = texture(tex, tc0).x; + float p1 = texture(tex, tc1).x; + float p2 = texture(tex, tc2).x; + float p3 = texture(tex, tc3).x; + + return normalize(vec3(p1-p2,4.0*delta,p0-p3)); +} void main() { - vec3 size = textureSize(tex, 0); - float prec = 0.5 / size.x; - vec2 c2 = clamp(vTexCoord.st, prec, 1.0-prec); - - float h0 = -10000.0;//texture(tex, vec3(c2, layers[0])).x; - float h1 = texture(tex, vec3(c2, layers[1])).x; - float h2 = texture(tex, vec3(c2, layers[2])).x; - float h3 = texture(tex, vec3(c2, layers[3])).x; - float h4 = texture(tex, vec3(c2, layers[4])).x; - float h5 = texture(tex, vec3(c2, layers[5])).x; - float h6 = texture(tex, vec3(c2, layers[6])).x; - float h7 = texture(tex, vec3(c2, layers[7])).x; - - out_Color0 = (h0); - out_Color1 = (h1); - out_Color2 = (h2); - out_Color3 = (h3); - out_Color4 = (h4); - out_Color5 = (h5); - out_Color6 = (h6); - out_Color7 = (h7); + vec3 s = textureSize(tex, 0); + float prec = 0.5 / s.x; + vec2 c2 = vTexCoord.st;//clamp(vTexCoord.st, prec, 1.0-prec); + + out_Color0 = computeNormal(vec3(c2, layers[0]), s.x); + out_Color1 = computeNormal(vec3(c2, layers[1]), s.x); + out_Color2 = computeNormal(vec3(c2, layers[2]), s.x); + out_Color3 = computeNormal(vec3(c2, layers[3]), s.x); + out_Color4 = computeNormal(vec3(c2, layers[4]), s.x); + out_Color5 = computeNormal(vec3(c2, layers[5]), s.x); + out_Color6 = computeNormal(vec3(c2, layers[6]), s.x); + out_Color7 = computeNormal(vec3(c2, layers[7]), s.x); } #endif diff --git a/shaders/perlin.glsl b/shaders/perlin.glsl old mode 100755 new mode 100644 diff --git a/shaders/post0.glsl b/shaders/post0.glsl old mode 100755 new mode 100644 diff --git a/shaders/post1.glsl b/shaders/post1.glsl old mode 100755 new mode 100644 index 585d24f..1c1e741 --- a/shaders/post1.glsl +++ b/shaders/post1.glsl @@ -1,21 +1,3 @@ -/*float4 ToneMapping( PS_INPUT psInput ) : SV_Target -{ - int2 iScreenCoord = int2(psInput.Tex * depthInfo.yz); - float4 sample = tex2D.Load(int3(iScreenCoord, 0)); - float4 ramp = colorramp.Sample(linearSampler, float2(cOffset, 0.f)); - sample.r += ramp.r - 0.5 * (ramp.g + ramp.b); - sample.g += ramp.g - 0.5 * (ramp.r + ramp.b); - sample.b += ramp.b - 0.5 * (ramp.r + ramp.g); - float Y = dot(sample, CIEXYZ); - float Yw = 0.95; - float Yp = exp(tex2D.Load(int3(0,0,maxMipmapLevel-1)).w); //adaptation luminance - float Yr = alpha * Y / Yp; - float D = (Yr * (1.0 + Yr / (Yw * Yw)) / (1 + Yr)); - return sample * D / Y; -} -*/ - - #version 400 core uniform sampler2D tex; @@ -39,16 +21,22 @@ void main(void) { in vec3 pass_TexCoord; out vec3 out_Color; uniform float alpha = 0.75; +uniform float maxMipLevel; + vec4 tonemap(vec4 color) { const vec3 luminace = vec3(0.2125f, 0.7154f, 0.0721f); float Y = dot(color.xyz, luminace); float Yw = 0.95; - float Yp = exp(textureLod(tex, vec2(0.5, 0.5), 10.0).w); //adaptation luminance + float Yp = exp(textureLod(tex, vec2(0.5, 0.5), maxMipLevel).w); //adaptation luminance float Yr = alpha * Y / Yp; float D = (Yr * (1.0 + Yr / (Yw * Yw)) / (1 + Yr)); return color * D / Y; } +vec4 ssao(vec2 texCoord) { + return vec4(0.0); +} + void main() { vec4 color = tonemap(texture(tex, pass_TexCoord.st)); out_Color = color.xyz; diff --git a/shaders/recttess.glsl b/shaders/recttess.glsl old mode 100755 new mode 100644 index cd2771b..ce29446 --- a/shaders/recttess.glsl +++ b/shaders/recttess.glsl @@ -3,7 +3,9 @@ uniform mat4 modelviewMatrix; uniform mat4 projMatrix; uniform sampler3D tex; +uniform sampler3D normalTex; uniform sampler2D waterTex; +uniform sampler2D testTex; uniform vec2 grid; uniform float D; uniform bool wireframe = false; @@ -13,6 +15,7 @@ uniform float waterLevel = 0.0; const float tile =0.015; const float attenuation = 0.075; uniform float LOD; + #ifdef _VERTEX_ in vec3 in_Position; in vec3 in_Normal; @@ -221,13 +224,19 @@ vec4 water(vec3 normal, vec4 pos) { vec3 reflDir = reflect(eyeDir, norm); vec4 transColor = vec4(0.0, 0.278, 0.321, 0.0); float cos_angle = max(dot(norm, eyeDir), 0.3); + vec4 waterColor = mix(baseColor, transColor*transColor, cos_angle); reflDir = normalize(reflDir); - vec4 atmoColor = atmosphere(reflDir); + vec4 atmoColor = atmosphere(reflDir)*1.5; + + float distance = length(cameraPos.xyz - pos.xyz); + distance *= .005; + distance = clamp(distance, 0, 1); //add foam if near shore + float lightAngle = max(dot(norm, lightPos), 0.8); - return mix(waterColor, atmoColor, 0.6); + return mix(waterColor, atmoColor, 0.6*distance); } float amplify(float d, float scale, float offset) { @@ -241,10 +250,10 @@ vec4 computeFFTNormal(vec2 pos, float atten) { float delta =(1.0/256.0); pos *= tile; - float p0 = texture(waterTex, (pos + vec2(0.0, -delta)) ).y * atten; - float p1 = texture(waterTex, (pos + vec2(-delta, 0.0) )).y * atten; - float p2 = texture(waterTex, (pos + vec2(delta, 0.0) ) ).y * atten; - float p3 = texture(waterTex, (pos + vec2(0.0, delta) ) ).y * atten; + float p0 = texture(waterTex, (pos + vec2(0.0,-delta)) ).y * atten; + float p1 = texture(waterTex, (pos + vec2(-delta,0.0) )).y * atten; + float p2 = texture(waterTex, (pos + vec2(delta,0.0) ) ).y * atten; + float p3 = texture(waterTex, (pos + vec2(0.0,delta) ) ).y * atten; return vec4(p1-p2,2.0*200.0*delta,p0-p3,0.0); } @@ -257,21 +266,29 @@ vec4 refractTerrain(vec3 disp, vec3 normal, float depth) { //fake refraction bas return vec4(.7, .7, .6, 1.0)*pVal; } + void main() { float h = texture(tex, fTexCoord).x; float pVal = (1.0-(h*0.01+0.25)); out_Color0 = vec4(.7, .7, .6, 1.0)*pVal + vec4(0.3, 0.5, 0.1, 1.0) * clamp((1.0-pVal-0.5), 0.0, 1.0); + out_Color0 = mix(texture(testTex, fTexCoord.st*8.0), out_Color0, min(pVal+0.1, 1.0)); + vec3 N = texture(normalTex, fTexCoord).xyz; + vec3 L = normalize(fPosition.xyz-lightPos); + float NL = dot(N, L)*0.25+1.3; + + out_Color0.xyz *= NL; + float dH = abs(h - waterLevel)*attenuation; float waterStrength = 1.0-clamp((-h*attenuation-waterLevel),0.0,1.0); if(waterStrength < 1.0) { vec3 I = fPosition.xyz - cameraPos.xyz; - vec3 N = computeFFTNormal(fPosition.xz, dH).xyz; + vec3 fftN = computeFFTNormal(fPosition.xz, dH).xyz; vec3 displacement = texture(waterTex, fPosition.xz*tile).xyz; - out_Color0 = mix(water(N, fPosition), - refractTerrain(displacement, N, dH), waterStrength); + out_Color0 = mix(water(fftN, fPosition), + refractTerrain(displacement, fftN, dH) * NL, waterStrength); } if(wireframe) { diff --git a/shaders/solid.glsl b/shaders/solid.glsl old mode 100755 new mode 100644 diff --git a/src/common.h b/src/common.h old mode 100755 new mode 100644 diff --git a/src/glcommon.h b/src/glcommon.h old mode 100755 new mode 100644 diff --git a/src/glengine.cpp b/src/glengine.cpp old mode 100755 new mode 100644 index 30343f1..faa79bf --- a/src/glengine.cpp +++ b/src/glengine.cpp @@ -6,13 +6,17 @@ #include "glshaderprogram.h" #include "keyboardcontroller.h" #include "glperlinterrain.h" +#include "gltextureloader.h" #include +#include +GLTextureLoader *GLTextureLoader::s_instance = 0; GLFramebufferObject *pMultisampleFramebuffer, *pFramebuffer0, *pFramebuffer1; GLPrimitive *pQuad; +void hello() {} GLEngine::GLEngine(WindowProperties &properties) { - - renderMode_ = FILL; + //std::thread t(hello); + //renderMode_ = FILL; //init gl setup vsml_ = VSML::getInstance(); @@ -48,7 +52,7 @@ GLEngine::GLEngine(WindowProperties &properties) { params.type = GL_TEXTURE_2D; pMultisampleFramebuffer = new GLFramebufferObject(params); - params.hasDepth = false; + params.hasDepth = true; params.nSamples = 0; pFramebuffer0 = new GLFramebufferObject(params); @@ -94,7 +98,7 @@ GLEngine::GLEngine(WindowProperties &properties) { shaderPrograms_["icosohedron"]->link(); GLPerlinTerrainParams paramsT; - paramsT.resolution = 128; + paramsT.resolution = 180; paramsT.gain = 0.61; paramsT.grid = float2(28,28); paramsT.lacunarity = 1.7; @@ -106,6 +110,7 @@ GLEngine::GLEngine(WindowProperties &properties) { lightPos_ = float3(1.0, 0.1, 0.0).getNormalized(); + } @@ -126,7 +131,7 @@ void GLEngine::resize(int w, int h) { pFramebuffer0->resize(width_, height_); pFramebuffer1->resize(width_, height_); - + camera_.orthogonal_camera(width_, height_); maxMipLevel_ = (log10((float)max(width_, height_)) / log10(2.f)); } @@ -157,11 +162,17 @@ void GLEngine::draw(float time, float dt, const KeyboardController *keyControlle primitives_["sphere0"]->draw(shaderPrograms_["icosohedron"]); shaderPrograms_["icosohedron"]->release(); glEnable(GL_DEPTH_TEST); + + // join fft computation thread + terrain_->draw(vsml_, time); + + // start next fft computation thread + glDrawBuffers(1, outputTex); pMultisampleFramebuffer->release(); pMultisampleFramebuffer->blit(*pFramebuffer0); - + glDisable(GL_DEPTH_TEST); this->vsmlOrtho(); shaderPrograms_["post0"]->bind(vsml_); @@ -172,7 +183,7 @@ void GLEngine::draw(float time, float dt, const KeyboardController *keyControlle pFramebuffer0->bindsurface(1); shaderPrograms_["post0"]->setUniformValue("posTex", 1); glActiveTexture(GL_TEXTURE0); - + pFramebuffer1->bind(); shaderPrograms_["post0"]->setUniformValue("modelviewMatrixPrev", previousViewMatrices[0]); shaderPrograms_["post0"]->setUniformValue("projMatrixPrev", previousViewMatrices[1]); @@ -187,15 +198,27 @@ void GLEngine::draw(float time, float dt, const KeyboardController *keyControlle shaderPrograms_["post1"]->bind(vsml_); glActiveTexture(GL_TEXTURE0); + pFramebuffer1->bindsurface(0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glGenerateMipmap(GL_TEXTURE_2D); + shaderPrograms_["post1"]->setUniformValue("tex", 0); - primitives_["quad1"]->draw(shaderPrograms_["default"]); + shaderPrograms_["post1"]->setUniformValue("maxMipLevel", (float)maxMipLevel_); + primitives_["quad1"]->draw(shaderPrograms_["post1"]); + shaderPrograms_["post1"]->release(); pFramebuffer1->unbindsurface(); - - camera_.orthogonal_camera(width_, height_); + + /* + glActiveTexture(GL_TEXTURE0); + pFramebuffer0->bindsurface(0); + shaderPrograms_["default"]->bind(vsml_); + shaderPrograms_["default"]->setUniformValue("tex", 0); + primitives_["quad1"]->draw(shaderPrograms_["default"]); + pFramebuffer0->unbindsurface(); + shaderPrograms_["default"]->release();*/ + } void GLEngine::vsmlOrtho() { diff --git a/src/glengine.h b/src/glengine.h old mode 100755 new mode 100644 index 3b27767..ebf8909 --- a/src/glengine.h +++ b/src/glengine.h @@ -63,6 +63,7 @@ class GLEngine VSML *vsml_; unordered_map, eqstr> shaderPrograms_; unordered_map primitives_; + RenderMode renderMode_; int maxMipLevel_; GLPerlinTerrain *terrain_; diff --git a/src/glfftwater.cpp b/src/glfftwater.cpp old mode 100755 new mode 100644 index 2446039..0a8eb41 --- a/src/glfftwater.cpp +++ b/src/glfftwater.cpp @@ -1,3 +1,4 @@ + #include "glfftwater.h" #include #include @@ -50,13 +51,13 @@ GLFFTWater::GLFFTWater(GLFFTWaterParams ¶ms) { m_kx[y*(hN+1)+x] = kx*k; } } -/* + if(!fftwf_init_threads()) { cerr << "Error initializing multithreaded fft." << endl; } else { - fftwf_plan_with_nthreads(2); + fftwf_plan_with_nthreads(4); } - */ + m_fftplan = fftwf_plan_dft_c2r_2d(m_params.N, m_params.N, (fftwf_complex *)m_h, m_h, FFTW_ESTIMATE); glGenTextures(1, &m_texId); @@ -68,11 +69,11 @@ GLFFTWater::GLFFTWater(GLFFTWaterParams ¶ms) { } float GLFFTWater::phillips(float kx, float ky, float& w) { - const float damping = 1.f / 1.f; + const float damping = 1.f / 2.f; float kk = kx*kx+ky*ky; float kw = kx*cosf(m_params.w)+ky*sinf(m_params.w); float l = m_params.V*m_params.V / 9.81; - w = powf((9.81*sqrtf(kk)),0.8f); //compute the dispersion relation + w = powf((9.81*sqrtf(kk)),1.0f); //compute the dispersion relation float p = m_params.A*expf(-1.f / (l*l*kk))/(kk*kk*kk)*(kw*kw); float d = expf(-kk*damping*damping); return kw < 0.f ? p*0.25f*d : p*d; @@ -119,6 +120,7 @@ float3 *GLFFTWater::computeHeightfield(float t) { m_dz[m_params.N + hNp2*hN] = 0.f; m_dx[m_params.N + hNp2*hN+1] = 0.f; m_dz[m_params.N + hNp2*hN+1] = 0.f; + fftwf_execute_dft_c2r(m_fftplan, (fftwf_complex *)m_h, m_h); fftwf_execute_dft_c2r(m_fftplan, (fftwf_complex *)m_dx, m_dx); diff --git a/src/glfftwater.h b/src/glfftwater.h old mode 100755 new mode 100644 diff --git a/src/glframebufferobject.cpp b/src/glframebufferobject.cpp old mode 100755 new mode 100644 index d8a02c7..cc76aac --- a/src/glframebufferobject.cpp +++ b/src/glframebufferobject.cpp @@ -1,11 +1,9 @@ #include "glframebufferobject.h" #include "glcommon.h" #include "common.h" - GLFramebufferObject::GLFramebufferObject(GLFramebufferObjectParams params) { - - params_ = params; + params_ = params; // @todo: should check the parameters to maker sure they make sense // instead were just going to check for a glError, if one of the parameters // is not correct it will probably result in a gl error diff --git a/src/glframebufferobject.h b/src/glframebufferobject.h old mode 100755 new mode 100644 index e9fee94..e792bcb --- a/src/glframebufferobject.h +++ b/src/glframebufferobject.h @@ -25,7 +25,7 @@ class GLFramebufferObject void bindsurface(int idx); void unbindsurface() { glBindTexture(params_.type, 0); } void release(); - + void resize(int width, int height); void blit(GLFramebufferObject &dst); /// blit contents into the destination framebuffer GLuint* texture(); diff --git a/src/glperlinterrain.cpp b/src/glperlinterrain.cpp old mode 100755 new mode 100644 index 3988039..b9e5311 --- a/src/glperlinterrain.cpp +++ b/src/glperlinterrain.cpp @@ -5,6 +5,8 @@ #include "glprimitive.h" #include "glframebufferobject.h" #include "glfftwater.h" +#include "gltextureloader.h" +#include GLPerlinTerrain::GLPerlinTerrain(GLPerlinTerrainParams ¶ms, GLEngine *engine) { params_ = params; engine_ = engine; @@ -36,6 +38,8 @@ GLPerlinTerrain::GLPerlinTerrain(GLPerlinTerrainParams ¶ms, GLEngine *engine lod_ = 13.f; + + this->generateTerrain(engine_->vsml()); } @@ -194,7 +198,7 @@ void GLPerlinTerrain::generateTerrain(VSML *vsml) { framebuffers_[i]->release(); } - /* + //create normal map glGenTextures(1, &normalmap_); @@ -204,7 +208,7 @@ void GLPerlinTerrain::generateTerrain(VSML *vsml) { glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP); - glTexImage3D(GL_TEXTURE_3D, 0, GL_R16F, params_.resolution, params_.resolution, + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F, params_.resolution, params_.resolution, instances_, 0, GL_LUMINANCE, GL_FLOAT, 0); glBindTexture(GL_TEXTURE_3D, 0); // manually attach 3d layers to the framebuffers @@ -217,8 +221,8 @@ void GLPerlinTerrain::generateTerrain(VSML *vsml) { } glBindTexture(GL_TEXTURE_3D, 0); framebuffers_[i]->release(); - }*/ - /* + } + lightingShader_ = new GLShaderProgram(); lightingShader_->loadShaderFromSource(GL_VERTEX_SHADER, "shaders/normals.glsl"); lightingShader_->loadShaderFromSource(GL_FRAGMENT_SHADER, "shaders/normals.glsl"); @@ -230,11 +234,11 @@ void GLPerlinTerrain::generateTerrain(VSML *vsml) { layers[i] = (i+0.5) / (float)instances_; } } - + for(int i=0; ibind(); - lightingShader_->bind(); + lightingShader_->bind(vsml); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_3D, heightmap_); lightingShader_->setUniformValue("tex", 0); @@ -256,7 +260,7 @@ void GLPerlinTerrain::generateTerrain(VSML *vsml) { } - */ + // glDrawBuffers(1, outputTex); @@ -269,6 +273,9 @@ void GLPerlinTerrain::generateTerrain(VSML *vsml) { delete[] offsets; //delete[] layers; + + GLTextureLoader::instance()->loadImage("textures/hello.bmp", "test", + GL_RGB, IL_RGB, IL_FLOAT); } @@ -284,6 +291,14 @@ void GLPerlinTerrain::draw(VSML *vsml, float time) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, tex); drawShader_->setUniformValue("waterTex", 1); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_3D, normalmap_); + drawShader_->setUniformValue("normalTex", 2); + + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, (*GLTextureLoader::instance()->textures())["test"].glTexId); + drawShader_->setUniformValue("testTex", 3); + if(engine_->renderMode() == WIREFRAME) drawShader_->setUniformValue("wireframe", true); else drawShader_->setUniformValue("wireframe", false); drawShader_->setUniformValue("cameraPos", engine_->camera()->eye); diff --git a/src/glperlinterrain.h b/src/glperlinterrain.h old mode 100755 new mode 100644 index 78ffcd6..6d0b975 --- a/src/glperlinterrain.h +++ b/src/glperlinterrain.h @@ -3,7 +3,9 @@ #include "common.h" #include "glcommon.h" +#include +using namespace std; class GLShaderProgram; class GLPrimitive; class GLFramebufferObject; @@ -42,6 +44,7 @@ class GLPerlinTerrain GLPrimitive *terrain_, *quad_; GLEngine *engine_; GLuint vboPosID_, vaoID_; + GLFFTWater *fftwater_; float lod_; }; diff --git a/src/glprimitive.cpp b/src/glprimitive.cpp old mode 100755 new mode 100644 diff --git a/src/glprimitive.h b/src/glprimitive.h old mode 100755 new mode 100644 diff --git a/src/glshaderprogram.cpp b/src/glshaderprogram.cpp old mode 100755 new mode 100644 diff --git a/src/glshaderprogram.h b/src/glshaderprogram.h old mode 100755 new mode 100644 diff --git a/src/keyboardcontroller.cpp b/src/keyboardcontroller.cpp old mode 100755 new mode 100644 diff --git a/src/keyboardcontroller.h b/src/keyboardcontroller.h old mode 100755 new mode 100644 diff --git a/src/main.cpp b/src/main.cpp old mode 100755 new mode 100644 index 0dd1a9e..9c69bd4 --- a/src/main.cpp +++ b/src/main.cpp @@ -145,7 +145,7 @@ double GetCounter() { QueryPerformanceCounter(&li); return double(li.QuadPart-CounterStart)/PCFreq; } - +#define GLEW_STATIC int main(int argc, char *argv[]) { WindowProperties properties = {1440, 900}; HDC hDC; /* device context */