diff --git a/jme3-android-native/libs/openalsoft/arm64-v8a/libopenalsoftjme.so b/jme3-android-native/libs/openalsoft/arm64-v8a/libopenalsoftjme.so
new file mode 100755
index 000000000..b85db58ec
Binary files /dev/null and b/jme3-android-native/libs/openalsoft/arm64-v8a/libopenalsoftjme.so differ
diff --git a/jme3-android-native/libs/openalsoft/armeabi-v7a/libopenalsoftjme.so b/jme3-android-native/libs/openalsoft/armeabi-v7a/libopenalsoftjme.so
old mode 100644
new mode 100755
index 04d4fd48f..5cdf3af9f
Binary files a/jme3-android-native/libs/openalsoft/armeabi-v7a/libopenalsoftjme.so and b/jme3-android-native/libs/openalsoft/armeabi-v7a/libopenalsoftjme.so differ
diff --git a/jme3-android-native/libs/openalsoft/armeabi/libopenalsoftjme.so b/jme3-android-native/libs/openalsoft/armeabi/libopenalsoftjme.so
old mode 100644
new mode 100755
index ff561809c..5205dec7e
Binary files a/jme3-android-native/libs/openalsoft/armeabi/libopenalsoftjme.so and b/jme3-android-native/libs/openalsoft/armeabi/libopenalsoftjme.so differ
diff --git a/jme3-android-native/libs/openalsoft/mips/libopenalsoftjme.so b/jme3-android-native/libs/openalsoft/mips/libopenalsoftjme.so
old mode 100644
new mode 100755
index 24f07dd22..ec3e9f747
Binary files a/jme3-android-native/libs/openalsoft/mips/libopenalsoftjme.so and b/jme3-android-native/libs/openalsoft/mips/libopenalsoftjme.so differ
diff --git a/jme3-android-native/libs/openalsoft/mips64/libopenalsoftjme.so b/jme3-android-native/libs/openalsoft/mips64/libopenalsoftjme.so
new file mode 100755
index 000000000..c523483a8
Binary files /dev/null and b/jme3-android-native/libs/openalsoft/mips64/libopenalsoftjme.so differ
diff --git a/jme3-android-native/libs/openalsoft/x86/libopenalsoftjme.so b/jme3-android-native/libs/openalsoft/x86/libopenalsoftjme.so
old mode 100644
new mode 100755
index 93e2029ad..cb2f480da
Binary files a/jme3-android-native/libs/openalsoft/x86/libopenalsoftjme.so and b/jme3-android-native/libs/openalsoft/x86/libopenalsoftjme.so differ
diff --git a/jme3-android-native/libs/openalsoft/x86_64/libopenalsoftjme.so b/jme3-android-native/libs/openalsoft/x86_64/libopenalsoftjme.so
new file mode 100755
index 000000000..53a04ef16
Binary files /dev/null and b/jme3-android-native/libs/openalsoft/x86_64/libopenalsoftjme.so differ
diff --git a/jme3-android-native/libs/stb_image/arm64-v8a/libstbijme.so b/jme3-android-native/libs/stb_image/arm64-v8a/libstbijme.so
new file mode 100755
index 000000000..6ecb94ff4
Binary files /dev/null and b/jme3-android-native/libs/stb_image/arm64-v8a/libstbijme.so differ
diff --git a/jme3-android-native/libs/stb_image/armeabi-v7a/libstbijme.so b/jme3-android-native/libs/stb_image/armeabi-v7a/libstbijme.so
old mode 100644
new mode 100755
index 225b5b701..58af1854c
Binary files a/jme3-android-native/libs/stb_image/armeabi-v7a/libstbijme.so and b/jme3-android-native/libs/stb_image/armeabi-v7a/libstbijme.so differ
diff --git a/jme3-android-native/libs/stb_image/armeabi/libstbijme.so b/jme3-android-native/libs/stb_image/armeabi/libstbijme.so
old mode 100644
new mode 100755
index 652b81474..a800d5210
Binary files a/jme3-android-native/libs/stb_image/armeabi/libstbijme.so and b/jme3-android-native/libs/stb_image/armeabi/libstbijme.so differ
diff --git a/jme3-android-native/libs/stb_image/mips/libstbijme.so b/jme3-android-native/libs/stb_image/mips/libstbijme.so
old mode 100644
new mode 100755
index 310e89902..d7267f7d0
Binary files a/jme3-android-native/libs/stb_image/mips/libstbijme.so and b/jme3-android-native/libs/stb_image/mips/libstbijme.so differ
diff --git a/jme3-android-native/libs/stb_image/mips64/libstbijme.so b/jme3-android-native/libs/stb_image/mips64/libstbijme.so
new file mode 100755
index 000000000..118945b15
Binary files /dev/null and b/jme3-android-native/libs/stb_image/mips64/libstbijme.so differ
diff --git a/jme3-android-native/libs/stb_image/x86/libstbijme.so b/jme3-android-native/libs/stb_image/x86/libstbijme.so
old mode 100644
new mode 100755
index 7ce477f27..e590a80f3
Binary files a/jme3-android-native/libs/stb_image/x86/libstbijme.so and b/jme3-android-native/libs/stb_image/x86/libstbijme.so differ
diff --git a/jme3-android-native/libs/stb_image/x86_64/libstbijme.so b/jme3-android-native/libs/stb_image/x86_64/libstbijme.so
new file mode 100755
index 000000000..c8d80c289
Binary files /dev/null and b/jme3-android-native/libs/stb_image/x86_64/libstbijme.so differ
diff --git a/jme3-android-native/openalsoft.gradle b/jme3-android-native/openalsoft.gradle
index 1027f44ef..d32a804b8 100644
--- a/jme3-android-native/openalsoft.gradle
+++ b/jme3-android-native/openalsoft.gradle
@@ -1,9 +1,5 @@
-// OpenAL Soft r1.15.1
-//String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/9b6a226da55a987cb883f425eeb568776ea12c8d.zip'
-// OpenAL Soft r1.15.1 + Android OpenSL Support
-String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/be25e6802dacad78876c6fa1d6a5c63797b8a9ed.zip'
-// OpenAL Soft r1.15.1 latest build (at the time)
-//String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/3f5914e0949ee12b504ee7254990e007ff8057ef.zip'
+// OpenAL Soft r1.16
+String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/e5016f814a265ed592a88acea95cf912c4bfdf12.zip'
String openALSoftZipFile = 'OpenALSoft.zip'
// OpenAL Soft directory the download is extracted into
@@ -81,22 +77,23 @@ task generateOpenAlSoftHeaders(dependsOn: copyJmeOpenALSoft) << {
String classes = ""
.concat("com.jme3.audio.android.AndroidOpenALSoftAudioRenderer, ")
// println "openalsoft classes = " + classes
-// println "openalsoft destDir = " + destDir
+// println "openalsoft destDir = " + destDirPath
// println "openalsoft classpath = " + project.projectClassPath
- ant.javah(
- classpath: project.projectClassPath,
- destdir: destDirPath,
- class: classes
- )
+ exec {
+ executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
+ args '-d', destDirPath
+ args '-classpath', project.projectClassPath
+ args "com.jme3.audio.android.AndroidOpenALSoftAudioRenderer"
+ }
}
task buildOpenAlSoftNativeLib(type: Exec, dependsOn: generateOpenAlSoftHeaders) {
// println "openalsoft build dir: " + openalsoftBuildDir
// println "ndkCommandPath: " + project.ndkCommandPath
- args 'TARGET_PLATFORM=android-9'
workingDir openalsoftBuildDir
executable rootProject.ndkCommandPath
+ args '-j8'
}
task updatePreCompiledOpenAlSoftLibs(type: Copy, dependsOn: buildOpenAlSoftNativeLib) {
diff --git a/jme3-android-native/src/native/jme_openalsoft/Android.mk b/jme3-android-native/src/native/jme_openalsoft/Android.mk
index 428008320..cac2e4df8 100644
--- a/jme3-android-native/src/native/jme_openalsoft/Android.mk
+++ b/jme3-android-native/src/native/jme_openalsoft/Android.mk
@@ -1,58 +1,68 @@
TARGET_PLATFORM := android-9
-ROOT_PATH := $(call my-dir)
-
-########################################################################################################
+LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := openalsoftjme
-LOCAL_ARM_MODE := arm
-LOCAL_PATH := $(ROOT_PATH)
-LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/include $(LOCAL_PATH)/OpenAL32/Include
-
-LOCAL_CFLAGS := -ffast-math -DAL_BUILD_LIBRARY -DAL_ALEXT_PROTOTYPES
-LOCAL_LDLIBS := -llog -Wl,-s
-LOCAL_LDLIBS += -lOpenSLES
-# LOCAL_CFLAGS += -DPOST_FROYO #-I$(ANDROID_NDK_ROOT)/platforms/android-9/arch-arm/usr/include/
-# LOCAL_LDLIBS += -ldl -L$(ANDROID_NDK_ROOT)/platforms/android-9/arch-arm/usr/lib/
-
-LOCAL_SRC_FILES := OpenAL32/alAuxEffectSlot.c \
- OpenAL32/alBuffer.c \
- OpenAL32/alEffect.c \
- OpenAL32/alError.c \
- OpenAL32/alExtension.c \
- OpenAL32/alFilter.c \
- OpenAL32/alListener.c \
- OpenAL32/alSource.c \
- OpenAL32/alState.c \
- OpenAL32/alThunk.c \
- Alc/ALc.c \
- Alc/ALu.c \
- Alc/alcConfig.c \
- Alc/alcDedicated.c \
- Alc/alcEcho.c \
- Alc/alcModulator.c \
- Alc/alcReverb.c \
- Alc/alcRing.c \
- Alc/alcThread.c \
- Alc/bs2b.c \
- Alc/helpers.c \
- Alc/panning.c \
- Alc/hrtf.c \
- Alc/mixer.c \
- Alc/mixer_c.c \
- Alc/backends/loopback.c \
- Alc/backends/null.c \
- Alc/backends/opensl.c \
- com_jme3_audio_android_AndroidOpenALSoftAudioRenderer.cpp
-# Alc/backends/alsa.c \
-# Alc/backends/android.c \
-# Alc/alcChorus.c \
-# Alc/alcFlanger.c \
-# Alc/mixer_c.c \
-# Alc/backends/loopback.c \
-# Alc/backends/null.c \
+
+LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/include \
+ $(LOCAL_PATH)/OpenAL32/Include $(LOCAL_PATH)/Alc
+
+LOCAL_CFLAGS := -std=c99 -ffast-math -DAL_BUILD_LIBRARY -DAL_ALEXT_PROTOTYPES
+LOCAL_LDLIBS := -lOpenSLES -llog -Wl,-s
+
+LOCAL_SRC_FILES := Alc/backends/opensl.c \
+ Alc/backends/loopback.c \
+ Alc/backends/wave.c \
+ Alc/backends/base.c \
+ Alc/backends/null.c \
+ Alc/ALc.c \
+ Alc/helpers.c \
+ Alc/bs2b.c \
+ Alc/alcRing.c \
+ Alc/effects/chorus.c \
+ Alc/effects/flanger.c \
+ Alc/effects/dedicated.c \
+ Alc/effects/reverb.c \
+ Alc/effects/distortion.c \
+ Alc/effects/autowah.c \
+ Alc/effects/equalizer.c \
+ Alc/effects/modulator.c \
+ Alc/effects/echo.c \
+ Alc/effects/compressor.c \
+ Alc/effects/null.c \
+ Alc/alcConfig.c \
+ Alc/ALu.c \
+ Alc/mixer_c.c \
+ Alc/panning.c \
+ Alc/hrtf.c \
+ Alc/mixer.c \
+ Alc/midi/soft.c \
+ Alc/midi/sf2load.c \
+ Alc/midi/dummy.c \
+ Alc/midi/fluidsynth.c \
+ Alc/midi/base.c \
+ common/uintmap.c \
+ common/atomic.c \
+ common/threads.c \
+ common/rwlock.c \
+ OpenAL32/alBuffer.c \
+ OpenAL32/alPreset.c \
+ OpenAL32/alListener.c \
+ OpenAL32/alEffect.c \
+ OpenAL32/alExtension.c \
+ OpenAL32/alThunk.c \
+ OpenAL32/alMidi.c \
+ OpenAL32/alSoundfont.c \
+ OpenAL32/alFontsound.c \
+ OpenAL32/alAuxEffectSlot.c \
+ OpenAL32/alError.c \
+ OpenAL32/alFilter.c \
+ OpenAL32/alSource.c \
+ OpenAL32/alState.c \
+ OpenAL32/sample_cvt.c \
+ com_jme3_audio_android_AndroidOpenALSoftAudioRenderer.cpp
include $(BUILD_SHARED_LIBRARY)
diff --git a/jme3-android-native/src/native/jme_openalsoft/Application.mk b/jme3-android-native/src/native/jme_openalsoft/Application.mk
index fcdc69644..fbc028f84 100644
--- a/jme3-android-native/src/native/jme_openalsoft/Application.mk
+++ b/jme3-android-native/src/native/jme_openalsoft/Application.mk
@@ -1,3 +1,3 @@
+APP_PLATFORM := android-9
APP_OPTIM := release
-APP_ABI := all
-#APP_ABI := armeabi-v7a
+APP_ABI := all
\ No newline at end of file
diff --git a/jme3-android-native/src/native/jme_openalsoft/config.h b/jme3-android-native/src/native/jme_openalsoft/config.h
index bf3ee85db..f9de99528 100644
--- a/jme3-android-native/src/native/jme_openalsoft/config.h
+++ b/jme3-android-native/src/native/jme_openalsoft/config.h
@@ -1,147 +1,203 @@
-#ifndef CONFIG_H
-#define CONFIG_H
+/* API declaration export attribute */
+#define AL_API __attribute__((visibility("protected")))
+#define ALC_API __attribute__((visibility("protected")))
/* Define to the library version */
-#define ALSOFT_VERSION "1.15.1"
+#define ALSOFT_VERSION "1.16.0"
-#define ALIGN(x) __attribute__ ((aligned(x)))
+#ifdef IN_IDE_PARSER
+/* KDevelop's parser doesn't recognize the C99-standard restrict keyword, but
+ * recent versions (at least 4.5.1) do recognize GCC's __restrict. */
+#define restrict __restrict
+#endif
-/* Define if we have the Android backend */
-/* #define HAVE_ANDROID 1 */
+/* Define any available alignment declaration */
+#define ALIGN(x) __attribute__((aligned(x)))
+
+/* Define if we have the C11 aligned_alloc function */
+/* #undef HAVE_ALIGNED_ALLOC */
+
+/* Define if we have the posix_memalign function */
+/* #undef HAVE_POSIX_MEMALIGN */
+
+/* Define if we have the _aligned_malloc function */
+/* #undef HAVE__ALIGNED_MALLOC */
+
+/* Define if we have SSE CPU extensions */
+/* #undef HAVE_SSE */
+/* #undef HAVE_SSE2 */
+/* #undef HAVE_SSE4_1 */
+
+/* Define if we have ARM Neon CPU extensions */
+/* #undef HAVE_NEON */
+
+/* Define if we have FluidSynth support */
+/* #undef HAVE_FLUIDSYNTH */
/* Define if we have the ALSA backend */
-/* #define HAVE_ALSA */
+/* #undef HAVE_ALSA */
/* Define if we have the OSS backend */
-/* #cmakedefine HAVE_OSS */
+/* #undef HAVE_OSS */
/* Define if we have the Solaris backend */
-/* #cmakedefine HAVE_SOLARIS */
+/* #undef HAVE_SOLARIS */
/* Define if we have the SndIO backend */
-/* #cmakedefine HAVE_SNDIO */
+/* #undef HAVE_SNDIO */
+
+/* Define if we have the QSA backend */
+/* #undef HAVE_QSA */
/* Define if we have the MMDevApi backend */
-/* #cmakedefine HAVE_MMDEVAPI */
+/* #undef HAVE_MMDEVAPI */
/* Define if we have the DSound backend */
-/* #cmakedefine HAVE_DSOUND */
+/* #undef HAVE_DSOUND */
/* Define if we have the Windows Multimedia backend */
-/* #cmakedefine HAVE_WINMM */
+/* #undef HAVE_WINMM */
/* Define if we have the PortAudio backend */
-/* #cmakedefine HAVE_PORTAUDIO */
+/* #undef HAVE_PORTAUDIO */
/* Define if we have the PulseAudio backend */
-/* #cmakedefine HAVE_PULSEAUDIO */
+/* #undef HAVE_PULSEAUDIO */
/* Define if we have the CoreAudio backend */
-/* #cmakedefine HAVE_COREAUDIO */
+/* #undef HAVE_COREAUDIO */
/* Define if we have the OpenSL backend */
-#define HAVE_OPENSL /* THIS BACKEND WORKS ON >=2.3 Android!! */
+#define HAVE_OPENSL
/* Define if we have the Wave Writer backend */
-/* #cmakedefine HAVE_WAVE */
-
-/* Define if we have dlfcn.h */
-#define HAVE_DLFCN_H
+#define HAVE_WAVE
/* Define if we have the stat function */
#define HAVE_STAT
-/* Define if we have the powf function */
-/* #define HAVE_POWF 1 */
+/* Define if we have the lrintf function */
+#define HAVE_LRINTF
-/* Define if we have the sqrtf function */
-/* #define HAVE_SQRTF 1 */
+/* Define if we have the strtof function */
+/* #undef HAVE_STRTOF */
-/* Define if we have the cosf function */
-/* #define HAVE_COSF 1 */
+/* Define if we have the __int64 type */
+/* #undef HAVE___INT64 */
-/* Define if we have the sinf function */
-/* #define HAVE_SINF 1 */
+/* Define to the size of a long int type */
+#define SIZEOF_LONG 4
-/* Define if we have the acosf function */
-/* #define HAVE_ACOSF 1 */
+/* Define to the size of a long long int type */
+#define SIZEOF_LONG_LONG 8
-/* Define if we have the asinf function */
-/* #define HAVE_ASINF 1 */
+/* Define if we have C99 variable-length array support */
+#define HAVE_C99_VLA
-/* Define if we have the atanf function */
-/* #define HAVE_ATANF 1 */
+/* Define if we have C99 _Bool support */
+#define HAVE_C99_BOOL
-/* Define if we have the atan2f function */
-/* #define HAVE_ATAN2F 1 */
+/* Define if we have C11 _Static_assert support */
+#define HAVE_C11_STATIC_ASSERT
-/* Define if we have the fabsf function */
-/* #define HAVE_FABSF 1 */
+/* Define if we have C11 _Alignas support */
+/* #undef HAVE_C11_ALIGNAS */
-/* Define if we have the log10f function */
-/* #define HAVE_LOG10F 1 */
+/* Define if we have C11 _Atomic support */
+/* #undef HAVE_C11_ATOMIC */
-/* Define if we have the floorf function */
-/* #define HAVE_FLOORF 1 */
+/* Define if we have GCC's destructor attribute */
+#define HAVE_GCC_DESTRUCTOR
-/* Define if we have the strtof function */
-#define HAVE_STRTOF
+/* Define if we have GCC's format attribute */
+#define HAVE_GCC_FORMAT
/* Define if we have stdint.h */
#define HAVE_STDINT_H
-/* Define if we have the __int64 type */
-/* #cmakedefine HAVE___INT64 */
+/* Define if we have stdbool.h */
+#define HAVE_STDBOOL_H
-/* Define to the size of a long int type */
-#define SIZEOF_LONG 4
+/* Define if we have stdalign.h */
+/* #undef HAVE_STDALIGN_H */
-/* Define to the size of a long long int type */
-#define SIZEOF_LONG_LONG 8
-
-/* Define if we have GCC's destructor attribute */
-#define HAVE_GCC_DESTRUCTOR
+/* Define if we have windows.h */
+/* #undef HAVE_WINDOWS_H */
-/* Define if we have GCC's format attribute */
-#define HAVE_GCC_FORMAT
+/* Define if we have dlfcn.h */
+#define HAVE_DLFCN_H
/* Define if we have pthread_np.h */
-/* #cmakedefine HAVE_PTHREAD_NP_H */
+/* #undef HAVE_PTHREAD_NP_H */
-/* Define if we have arm_neon.h */
-/* #cmakedefine HAVE_ARM_NEON_H */
+/* Define if we have alloca.h */
+/* #undef HAVE_ALLOCA_H */
-/* Define if we have guiddef.h */
-/* #cmakedefine HAVE_GUIDDEF_H */
+/* Define if we have malloc.h */
+#define HAVE_MALLOC_H
+
+/* Define if we have ftw.h */
+/* #undef HAVE_FTW_H */
+
+/* Define if we have io.h */
+/* #undef HAVE_IO_H */
+
+/* Define if we have strings.h */
+#define HAVE_STRINGS_H
+
+/* Define if we have cpuid.h */
+/* #undef HAVE_CPUID_H */
+
+/* Define if we have intrin.h */
+/* #undef HAVE_INTRIN_H */
+
+/* Define if we have sys/sysconf.h */
+#define HAVE_SYS_SYSCONF_H
/* Define if we have guiddef.h */
-/* #cmakedefine HAVE_INITGUID_H */
+/* #undef HAVE_GUIDDEF_H */
+
+/* Define if we have initguid.h */
+/* #undef HAVE_INITGUID_H */
/* Define if we have ieeefp.h */
-/* #cmakedefine HAVE_IEEEFP_H */
+/* #undef HAVE_IEEEFP_H */
/* Define if we have float.h */
-/* #cmakedefine HAVE_FLOAT_H */
-
-/* Define if we have fpu_control.h */
-/* #cmakedefine HAVE_FPU_CONTROL_H */
+#define HAVE_FLOAT_H
/* Define if we have fenv.h */
#define HAVE_FENV_H
-/* Define if we have fesetround() */
-/* #cmakedefine HAVE_FESETROUND */
+/* Define if we have GCC's __get_cpuid() */
+/* #undef HAVE_GCC_GET_CPUID */
+
+/* Define if we have the __cpuid() intrinsic */
+/* #undef HAVE_CPUID_INTRINSIC */
/* Define if we have _controlfp() */
-/* #cmakedefine HAVE__CONTROLFP */
+/* #undef HAVE__CONTROLFP */
+
+/* Define if we have __control87_2() */
+/* #undef HAVE___CONTROL87_2 */
+
+/* Define if we have ftw() */
+/* #undef HAVE_FTW */
+
+/* Define if we have _wfindfirst() */
+/* #undef HAVE__WFINDFIRST */
/* Define if we have pthread_setschedparam() */
#define HAVE_PTHREAD_SETSCHEDPARAM
-/* Define if we have the restrict keyword */
-/* #cmakedefine HAVE_RESTRICT 1 */
+/* Define if we have pthread_setname_np() */
+#define HAVE_PTHREAD_SETNAME_NP
+
+/* Define if we have pthread_set_name_np() */
+/* #undef HAVE_PTHREAD_SET_NAME_NP */
-/* Define if we have the __restrict keyword */
-#define RESTRICT __restrict
+/* Define if we have pthread_mutexattr_setkind_np() */
+/* #undef HAVE_PTHREAD_MUTEXATTR_SETKIND_NP */
-#endif
+/* Define if we have pthread_mutex_timedlock() */
+/* #undef HAVE_PTHREAD_MUTEX_TIMEDLOCK */
\ No newline at end of file
diff --git a/jme3-android-native/src/native/jme_stbi/Android.mk b/jme3-android-native/src/native/jme_stbi/Android.mk
index ba8a4e64e..469c63e4d 100644
--- a/jme3-android-native/src/native/jme_stbi/Android.mk
+++ b/jme3-android-native/src/native/jme_stbi/Android.mk
@@ -1,13 +1,15 @@
+TARGET_PLATFORM := android-9
+
LOCAL_PATH := $(call my-dir)
+
include $(CLEAR_VARS)
LOCAL_MODULE := stbijme
-LOCAL_C_INCLUDES := $(LOCAL_PATH)
-LOCAL_CFLAGS += -O2
-LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
-LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,, $(wildcard $(LOCAL_PATH)/*.c))
-
-#adds zlib
-LOCAL_LDLIBS += -lz -llog
+
+LOCAL_C_INCLUDES += $(LOCAL_PATH)
+
+LOCAL_LDLIBS := -lz -llog -Wl,-s
+
+LOCAL_SRC_FILES := com_jme3_texture_plugins_AndroidNativeImageLoader.c
include $(BUILD_SHARED_LIBRARY)
diff --git a/jme3-android-native/src/native/jme_stbi/Application.mk b/jme3-android-native/src/native/jme_stbi/Application.mk
index fcdc69644..fbc028f84 100644
--- a/jme3-android-native/src/native/jme_stbi/Application.mk
+++ b/jme3-android-native/src/native/jme_stbi/Application.mk
@@ -1,3 +1,3 @@
+APP_PLATFORM := android-9
APP_OPTIM := release
-APP_ABI := all
-#APP_ABI := armeabi-v7a
+APP_ABI := all
\ No newline at end of file
diff --git a/jme3-android-native/src/native/jme_stbi/com_jme3_texture_plugins_AndroidNativeImageLoader.c b/jme3-android-native/src/native/jme_stbi/com_jme3_texture_plugins_AndroidNativeImageLoader.c
index 45dbed0b0..a4064a622 100644
--- a/jme3-android-native/src/native/jme_stbi/com_jme3_texture_plugins_AndroidNativeImageLoader.c
+++ b/jme3-android-native/src/native/jme_stbi/com_jme3_texture_plugins_AndroidNativeImageLoader.c
@@ -6,8 +6,9 @@
#include AndroidGLSurfaceView
is derived from GLSurfaceView
- * @author iwgeric
- *
- */
-public class AndroidGLSurfaceView extends GLSurfaceView {
-
- private final static Logger logger = Logger.getLogger(AndroidGLSurfaceView.class.getName());
-
- public AndroidGLSurfaceView(Context ctx, AttributeSet attribs) {
- super(ctx, attribs);
- }
-
- public AndroidGLSurfaceView(Context ctx) {
- super(ctx);
- }
-
-
-}
\ No newline at end of file
diff --git a/jme3-android/src/main/java/com/jme3/system/android/AndroidTimer.java b/jme3-android/src/main/java/com/jme3/system/android/AndroidTimer.java
deleted file mode 100644
index 965895c41..000000000
--- a/jme3-android/src/main/java/com/jme3/system/android/AndroidTimer.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2009-2012 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * 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.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "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 COPYRIGHT OWNER OR
- * CONTRIBUTORS 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.
- */
-
-package com.jme3.system.android;
-
-import com.jme3.system.Timer;
-
-/**
- * AndroidTimer
is a System.nanoTime implementation of Timer
.
- */
-public class AndroidTimer extends Timer {
-
- //private static final long TIMER_RESOLUTION = 1000L;
- //private static final float INVERSE_TIMER_RESOLUTION = 1f/1000L;
- private static final long TIMER_RESOLUTION = 1000000000L;
- private static final float INVERSE_TIMER_RESOLUTION = 1f/1000000000L;
-
- private long startTime;
- private long previousTime;
- private float tpf;
- private float fps;
-
- public AndroidTimer() {
- //startTime = System.currentTimeMillis();
- startTime = System.nanoTime();
- }
-
- /**
- * Returns the time in seconds. The timer starts
- * at 0.0 seconds.
- *
- * @return the current time in seconds
- */
- @Override
- public float getTimeInSeconds() {
- return getTime() * INVERSE_TIMER_RESOLUTION;
- }
-
- public long getTime() {
- //return System.currentTimeMillis() - startTime;
- return System.nanoTime() - startTime;
- }
-
- public long getResolution() {
- return TIMER_RESOLUTION;
- }
-
- public float getFrameRate() {
- return fps;
- }
-
- public float getTimePerFrame() {
- return tpf;
- }
-
- public void update() {
- tpf = (getTime() - previousTime) * (1.0f / TIMER_RESOLUTION);
- fps = 1.0f / tpf;
- previousTime = getTime();
- }
-
- public void reset() {
- //startTime = System.currentTimeMillis();
- startTime = System.nanoTime();
- previousTime = getTime();
- }
-}
diff --git a/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java b/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java
index cf49c1cee..a01d1a480 100644
--- a/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java
+++ b/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java
@@ -47,13 +47,11 @@ import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.FrameLayout;
import com.jme3.input.*;
-import com.jme3.input.android.AndroidInput;
import com.jme3.input.android.AndroidSensorJoyInput;
import com.jme3.input.android.AndroidInputHandler;
import com.jme3.input.controls.SoftTextDialogInputListener;
import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput;
-import com.jme3.renderer.android.AndroidGLSurfaceView;
import com.jme3.renderer.android.OGLESShaderRenderer;
import com.jme3.system.*;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -80,11 +78,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
protected AndroidInputHandler androidInput;
protected int minFrameDuration = 0; // No FPS cap
protected JoyInput androidSensorJoyInput = null;
- /**
- * EGL_RENDERABLE_TYPE: EGL_OPENGL_ES_BIT = OpenGL ES 1.0 |
- * EGL_OPENGL_ES2_BIT = OpenGL ES 2.0
- */
- protected int clientOpenGLESVersion = 1;
public OGLESContext() {
}
@@ -103,12 +96,17 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
*
* @return GLSurfaceView The newly created view
*/
- public AndroidGLSurfaceView createView() {
- AndroidGLSurfaceView view;
- int buildVersion = Build.VERSION.SDK_INT;
-
+ public GLSurfaceView createView() {
+ Context appContext = JmeAndroidSystem.getActivity().getApplication();
+
+ ActivityManager am = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
+ ConfigurationInfo info = am.getDeviceConfigurationInfo();
+ if (info.reqGlEsVersion < 0x20000) {
+ throw new UnsupportedOperationException("OpenGL ES 2.0 is not supported on this device");
+ }
+
// Start to set up the view
- view = new AndroidGLSurfaceView(JmeAndroidSystem.getActivity().getApplication());
+ GLSurfaceView view = new GLSurfaceView(appContext);
if (androidInput == null) {
androidInput = new AndroidInputHandler();
}
@@ -117,20 +115,11 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
// setEGLContextClientVersion must be set before calling setRenderer
// this means it cannot be set in AndroidConfigChooser (too late)
- int rawOpenGLESVersion = getOpenGLESVersion();
-// logger.log(Level.FINE, "clientOpenGLESVersion {0}.{1}",
-// new Object[]{clientOpenGLESVersion>>16, clientOpenGLESVersion<<16});
- if (rawOpenGLESVersion < 0x20000) {
- throw new UnsupportedOperationException("OpenGL ES 2.0 is not supported on this device");
- } else {
- clientOpenGLESVersion = 2;
- view.setEGLContextClientVersion(clientOpenGLESVersion);
- }
+ view.setEGLContextClientVersion(2);
view.setFocusableInTouchMode(true);
view.setFocusable(true);
- view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);
-
+
// setFormat must be set before AndroidConfigChooser is called by the surfaceview.
// if setFormat is called after ConfigChooser is called, then execution
// stops at the setFormat call without a crash.
@@ -160,25 +149,13 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
// Not destroying and recreating the EGL context
// will help with resume time by reusing the existing context to avoid
// reloading all the OpenGL objects.
- if (buildVersion >= 11) {
+ if (Build.VERSION.SDK_INT >= 11) {
view.setPreserveEGLContextOnPause(true);
}
return view;
}
- /**
- * Get the OpenGL ES version
- * @return version returns the int value of the GLES version
- */
- public int getOpenGLESVersion() {
- ActivityManager am =
- (ActivityManager) JmeAndroidSystem.getActivity().getApplication().getSystemService(Context.ACTIVITY_SERVICE);
- ConfigurationInfo info = am.getDeviceConfigurationInfo();
- logger.log(Level.FINE, "OpenGL Version {0}:", info.getGlEsVersion());
- return info.reqGlEsVersion;
-// return (info.reqGlEsVersion >= 0x20000);
- }
-
+
// renderer:initialize
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig cfg) {
@@ -207,7 +184,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
}
});
- timer = new AndroidTimer();
+ timer = new NanoTimer();
renderer = new OGLESShaderRenderer();
renderer.initialize();
diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java
index 20fcd1e9a..489139ef5 100644
--- a/jme3-core/src/main/java/com/jme3/material/Material.java
+++ b/jme3-core/src/main/java/com/jme3/material/Material.java
@@ -42,7 +42,6 @@ import com.jme3.material.TechniqueDef.LightMode;
import com.jme3.material.TechniqueDef.ShadowMode;
import com.jme3.math.*;
import com.jme3.renderer.Caps;
-import com.jme3.renderer.GL1Renderer;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.Renderer;
import com.jme3.renderer.RendererException;
@@ -52,7 +51,6 @@ import com.jme3.scene.Mesh;
import com.jme3.scene.instancing.InstancedGeometry;
import com.jme3.shader.Shader;
import com.jme3.shader.Uniform;
-import com.jme3.shader.UniformBindingManager;
import com.jme3.shader.VarType;
import com.jme3.texture.Texture;
import com.jme3.texture.image.ColorSpace;
@@ -697,12 +695,15 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
setParam(name, VarType.Vector4, value);
}
- private ColorRGBA getAmbientColor(LightList lightList) {
+ private ColorRGBA getAmbientColor(LightList lightList, boolean removeLights) {
ambientLightColor.set(0, 0, 0, 1);
for (int j = 0; j < lightList.size(); j++) {
Light l = lightList.get(j);
if (l instanceof AmbientLight) {
ambientLightColor.addLocal(l.getColor());
+ if(removeLights){
+ lightList.remove(l);
+ }
}
}
ambientLightColor.a = 1.0f;
@@ -741,75 +742,106 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
* g_LightPosition.w is the inverse radius (1/r) of the light (for
* attenuation)
diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag
index e4773c8cf..a1f58b898 100644
--- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag
+++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag
@@ -1,7 +1,9 @@
#import "Common/ShaderLib/Parallax.glsllib"
#import "Common/ShaderLib/Optics.glsllib"
-#define ATTENUATION
-//#define HQ_ATTENUATION
+#ifndef VERTEX_LIGHTING
+ #import "Common/ShaderLib/PhongLighting.glsllib"
+ #import "Common/ShaderLib/Lighting.glsllib"
+#endif
varying vec2 texCoord;
#ifdef SEPARATE_TEXCOORD
@@ -58,82 +60,14 @@ varying vec3 SpecularSum;
uniform float m_AlphaDiscardThreshold;
#ifndef VERTEX_LIGHTING
-uniform float m_Shininess;
-
-#ifdef HQ_ATTENUATION
-uniform vec4 g_LightPosition;
-#endif
+ uniform float m_Shininess;
+ #ifdef USE_REFLECTION
+ uniform float m_ReflectionPower;
+ uniform float m_ReflectionIntensity;
+ varying vec4 refVec;
-#ifdef USE_REFLECTION
- uniform float m_ReflectionPower;
- uniform float m_ReflectionIntensity;
- varying vec4 refVec;
-
- uniform ENVMAP m_EnvMap;
-#endif
-
-float tangDot(in vec3 v1, in vec3 v2){
- float d = dot(v1,v2);
- #ifdef V_TANGENT
- d = 1.0 - d*d;
- return step(0.0, d) * sqrt(d);
- #else
- return d;
+ uniform ENVMAP m_EnvMap;
#endif
-}
-
-float lightComputeDiffuse(in vec3 norm, in vec3 lightdir, in vec3 viewdir){
- #ifdef MINNAERT
- float NdotL = max(0.0, dot(norm, lightdir));
- float NdotV = max(0.0, dot(norm, viewdir));
- return NdotL * pow(max(NdotL * NdotV, 0.1), -1.0) * 0.5;
- #else
- return max(0.0, dot(norm, lightdir));
- #endif
-}
-
-float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
- // NOTE: check for shiny <= 1 removed since shininess is now
- // 1.0 by default (uses matdefs default vals)
- #ifdef LOW_QUALITY
- // Blinn-Phong
- // Note: preferably, H should be computed in the vertex shader
- vec3 H = (viewdir + lightdir) * vec3(0.5);
- return pow(max(tangDot(H, norm), 0.0), shiny);
- #elif defined(WARDISO)
- // Isotropic Ward
- vec3 halfVec = normalize(viewdir + lightdir);
- float NdotH = max(0.001, tangDot(norm, halfVec));
- float NdotV = max(0.001, tangDot(norm, viewdir));
- float NdotL = max(0.001, tangDot(norm, lightdir));
- float a = tan(acos(NdotH));
- float p = max(shiny/128.0, 0.001);
- return NdotL * (1.0 / (4.0*3.14159265*p*p)) * (exp(-(a*a)/(p*p)) / (sqrt(NdotV * NdotL)));
- #else
- // Standard Phong
- vec3 R = reflect(-lightdir, norm);
- return pow(max(tangDot(R, viewdir), 0.0), shiny);
- #endif
-}
-
-vec2 computeLighting(in vec3 wvNorm, in vec3 wvViewDir, in vec3 wvLightDir){
- float diffuseFactor = lightComputeDiffuse(wvNorm, wvLightDir, wvViewDir);
- float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir, m_Shininess);
-
- #ifdef HQ_ATTENUATION
- float att = clamp(1.0 - g_LightPosition.w * length(lightVec), 0.0, 1.0);
- #else
- float att = vLightDir.w;
- #endif
-
- if (m_Shininess <= 1.0) {
- specularFactor = 0.0; // should be one instruction on most cards ..
- }
-
- specularFactor *= diffuseFactor;
-
- return vec2(diffuseFactor, specularFactor) * vec2(att);
-}
#endif
void main(){
@@ -172,40 +106,13 @@ void main(){
#ifdef ALPHAMAP
alpha = alpha * texture2D(m_AlphaMap, newTexCoord).r;
#endif
- if(alpha < m_AlphaDiscardThreshold){
- discard;
- }
-
- #ifndef VERTEX_LIGHTING
- float spotFallOff = 1.0;
-
- #if __VERSION__ >= 110
- // allow use of control flow
- if(g_LightDirection.w != 0.0){
- #endif
+ #ifdef DISCARD_ALPHA
+ if(alpha < m_AlphaDiscardThreshold){
+ discard;
+ }
+ #endif
- vec3 L = normalize(lightVec.xyz);
- vec3 spotdir = normalize(g_LightDirection.xyz);
- float curAngleCos = dot(-L, spotdir);
- float innerAngleCos = floor(g_LightDirection.w) * 0.001;
- float outerAngleCos = fract(g_LightDirection.w);
- float innerMinusOuter = innerAngleCos - outerAngleCos;
- spotFallOff = (curAngleCos - outerAngleCos) / innerMinusOuter;
- #if __VERSION__ >= 110
- if(spotFallOff <= 0.0){
- gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;
- gl_FragColor.a = alpha;
- return;
- }else{
- spotFallOff = clamp(spotFallOff, 0.0, 1.0);
- }
- }
- #else
- spotFallOff = clamp(spotFallOff, step(g_LightDirection.w, 0.001), 1.0);
- #endif
- #endif
-
// ***********************
// Read from textures
// ***********************
@@ -257,8 +164,23 @@ void main(){
vec4 lightDir = vLightDir;
lightDir.xyz = normalize(lightDir.xyz);
vec3 viewDir = normalize(vViewDir);
+ float spotFallOff = 1.0;
+
+ #if __VERSION__ >= 110
+ // allow use of control flow
+ if(g_LightDirection.w != 0.0){
+ #endif
+ spotFallOff = computeSpotFalloff(g_LightDirection, lightVec);
+ #if __VERSION__ >= 110
+ if(spotFallOff <= 0.0){
+ gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;
+ gl_FragColor.a = alpha;
+ return;
+ }
+ }
+ #endif
- vec2 light = computeLighting(normal, viewDir, lightDir.xyz) * spotFallOff;
+ vec2 light = computeLighting(normal, viewDir, lightDir.xyz, lightDir.w * spotFallOff, m_Shininess) ;
#ifdef COLORRAMP
diffuseColor.rgb *= texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb;
specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb;
diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md
index 779242445..e5613f040 100644
--- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md
+++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md
@@ -6,34 +6,12 @@ MaterialDef Phong Lighting {
// For better performance
Boolean VertexLighting
- // Use more efficent algorithms to improve performance
- Boolean LowQuality
-
- // Improve quality at the cost of performance
- Boolean HighQuality
-
- // Output alpha from the diffuse map
- Boolean UseAlpha
-
// Alpha threshold for fragment discarding
Float AlphaDiscardThreshold (AlphaTestFallOff)
- // Normal map is in BC5/ATI2n/LATC/3Dc compression format
- Boolean LATC
-
// Use the provided ambient, diffuse, and specular colors
Boolean UseMaterialColors
- // Activate shading along the tangent, instead of the normal
- // Requires tangent data to be available on the model.
- Boolean VTangent
-
- // Use minnaert diffuse instead of lambert
- Boolean Minnaert
-
- // Use ward specular instead of phong
- Boolean WardIso
-
// Use vertex color as an additional diffuse color.
Boolean UseVertexColor
@@ -133,9 +111,48 @@ MaterialDef Phong Lighting {
Int NumberOfBones
Matrix4Array BoneMatrices
+ //For instancing
Boolean UseInstancing
}
+ Technique {
+ LightMode SinglePass
+
+ VertexShader GLSL100: Common/MatDefs/Light/SPLighting.vert
+ FragmentShader GLSL100: Common/MatDefs/Light/SPLighting.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ NormalMatrix
+ WorldViewMatrix
+ ViewMatrix
+ CameraPosition
+ WorldMatrix
+ ViewProjectionMatrix
+ }
+
+ Defines {
+ VERTEX_COLOR : UseVertexColor
+ VERTEX_LIGHTING : VertexLighting
+ MATERIAL_COLORS : UseMaterialColors
+ DIFFUSEMAP : DiffuseMap
+ NORMALMAP : NormalMap
+ SPECULARMAP : SpecularMap
+ PARALLAXMAP : ParallaxMap
+ NORMALMAP_PARALLAX : PackedNormalParallax
+ STEEP_PARALLAX : SteepParallax
+ ALPHAMAP : AlphaMap
+ COLORRAMP : ColorRamp
+ LIGHTMAP : LightMap
+ SEPARATE_TEXCOORD : SeparateTexCoord
+ DISCARD_ALPHA : AlphaDiscardThreshold
+ USE_REFLECTION : EnvMap
+ SPHERE_MAP : SphereMap
+ NUM_BONES : NumberOfBones
+ INSTANCING : UseInstancing
+ }
+ }
+
Technique {
LightMode MultiPass
@@ -154,17 +171,9 @@ MaterialDef Phong Lighting {
}
Defines {
- LATC : LATC
VERTEX_COLOR : UseVertexColor
- VERTEX_LIGHTING : VertexLighting
- ATTENUATION : Attenuation
+ VERTEX_LIGHTING : VertexLighting
MATERIAL_COLORS : UseMaterialColors
- V_TANGENT : VTangent
- MINNAERT : Minnaert
- WARDISO : WardIso
- LOW_QUALITY : LowQuality
- HQ_ATTENUATION : HighQuality
-
DIFFUSEMAP : DiffuseMap
NORMALMAP : NormalMap
SPECULARMAP : SpecularMap
@@ -175,16 +184,16 @@ MaterialDef Phong Lighting {
COLORRAMP : ColorRamp
LIGHTMAP : LightMap
SEPARATE_TEXCOORD : SeparateTexCoord
-
+ DISCARD_ALPHA : AlphaDiscardThreshold
USE_REFLECTION : EnvMap
SPHERE_MAP : SphereMap
-
- NUM_BONES : NumberOfBones
-
+ NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}
+
+
Technique PreShadow {
VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
@@ -373,4 +382,4 @@ MaterialDef Phong Lighting {
}
}
-}
\ No newline at end of file
+}
diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert
index 737786fb4..1901ebc67 100644
--- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert
+++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert
@@ -1,8 +1,10 @@
#import "Common/ShaderLib/Instancing.glsllib"
-#define ATTENUATION
-//#define HQ_ATTENUATION
-
#import "Common/ShaderLib/Skinning.glsllib"
+#import "Common/ShaderLib/Lighting.glsllib"
+#ifdef VERTEX_LIGHTING
+ #import "Common/ShaderLib/PhongLighting.glsllib"
+#endif
+
uniform vec4 m_Ambient;
uniform vec4 m_Diffuse;
@@ -28,7 +30,6 @@ attribute vec2 inTexCoord;
attribute vec3 inNormal;
varying vec3 lightVec;
-//varying vec4 spotVec;
#ifdef VERTEX_COLOR
attribute vec4 inColor;
@@ -39,8 +40,7 @@ varying vec3 lightVec;
#ifndef NORMALMAP
varying vec3 vNormal;
- #endif
- //varying vec3 vPosition;
+ #endif
varying vec3 vViewDir;
varying vec4 vLightDir;
#else
@@ -77,57 +77,6 @@ varying vec3 lightVec;
}
#endif
-// JME3 lights in world space
-void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
- float posLight = step(0.5, color.w);
- vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
- lightVec = tempVec;
- #ifdef ATTENUATION
- float dist = length(tempVec);
- lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
- lightDir.xyz = tempVec / vec3(dist);
- #else
- lightDir = vec4(normalize(tempVec), 1.0);
- #endif
-}
-
-#ifdef VERTEX_LIGHTING
- float lightComputeDiffuse(in vec3 norm, in vec3 lightdir){
- return max(0.0, dot(norm, lightdir));
- }
-
- float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
- if (shiny <= 1.0){
- return 0.0;
- }
- #ifndef LOW_QUALITY
- vec3 H = (viewdir + lightdir) * vec3(0.5);
- return pow(max(dot(H, norm), 0.0), shiny);
- #else
- return 0.0;
- #endif
- }
-
-vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec4 wvLightPos){
- vec4 lightDir;
- lightComputeDir(wvPos, g_LightColor, wvLightPos, lightDir);
- float spotFallOff = 1.0;
- if(g_LightDirection.w != 0.0){
- vec3 L=normalize(lightVec.xyz);
- vec3 spotdir = normalize(g_LightDirection.xyz);
- float curAngleCos = dot(-L, spotdir);
- float innerAngleCos = floor(g_LightDirection.w) * 0.001;
- float outerAngleCos = fract(g_LightDirection.w);
- float innerMinusOuter = innerAngleCos - outerAngleCos;
- spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0);
- }
- float diffuseFactor = lightComputeDiffuse(wvNorm, lightDir.xyz);
- float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, lightDir.xyz, m_Shininess);
- //specularFactor *= step(0.01, diffuseFactor);
- return vec2(diffuseFactor, specularFactor) * vec2(lightDir.w)*spotFallOff;
- }
-#endif
-
void main(){
vec4 modelSpacePos = vec4(inPosition, 1.0);
vec3 modelSpaceNorm = inNormal;
@@ -154,11 +103,6 @@ void main(){
vec3 wvNormal = normalize(TransformNormal(modelSpaceNorm));//normalize(g_NormalMatrix * modelSpaceNorm);
vec3 viewDir = normalize(-wvPosition);
- //vec4 lightColor = g_LightColor[gl_InstanceID];
- //vec4 lightPos = g_LightPosition[gl_InstanceID];
- //vec4 wvLightPos = (g_ViewMatrix * vec4(lightPos.xyz, lightColor.w));
- //wvLightPos.w = lightPos.w;
-
vec4 wvLightPos = (g_ViewMatrix * vec4(g_LightPosition.xyz,clamp(g_LightColor.w,0.0,1.0)));
wvLightPos.w = g_LightPosition.w;
vec4 lightColor = g_LightColor;
@@ -166,41 +110,24 @@ void main(){
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vec3 wvTangent = normalize(TransformNormal(modelSpaceTan));
vec3 wvBinormal = cross(wvNormal, wvTangent);
-
mat3 tbnMat = mat3(wvTangent, wvBinormal * inTangent.w,wvNormal);
-
- //vPosition = wvPosition * tbnMat;
- //vViewDir = viewDir * tbnMat;
+
vViewDir = -wvPosition * tbnMat;
- lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
+ lightComputeDir(wvPosition, lightColor.w, wvLightPos, vLightDir, lightVec);
vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
#elif !defined(VERTEX_LIGHTING)
vNormal = wvNormal;
-
- //vPosition = wvPosition;
vViewDir = viewDir;
-
- lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
-
- #ifdef V_TANGENT
- vNormal = normalize(TransformNormal(inTangent.xyz));
- vNormal = -cross(cross(vLightDir.xyz, vNormal), vNormal);
- #endif
+ lightComputeDir(wvPosition, lightColor.w, wvLightPos, vLightDir, lightVec);
#endif
- //computing spot direction in view space and unpacking spotlight cos
-// spotVec = (g_ViewMatrix * vec4(g_LightDirection.xyz, 0.0) );
-// spotVec.w = floor(g_LightDirection.w) * 0.001;
-// lightVec.w = fract(g_LightDirection.w);
-
- lightColor.w = 1.0;
#ifdef MATERIAL_COLORS
AmbientSum = (m_Ambient * g_AmbientLightColor).rgb;
- DiffuseSum = m_Diffuse * lightColor;
+ DiffuseSum = m_Diffuse * vec4(lightColor.rgb, 1.0);
SpecularSum = (m_Specular * lightColor).rgb;
#else
- AmbientSum = vec3(0.2, 0.2, 0.2) * g_AmbientLightColor.rgb; // Default: ambient color is dark gray
- DiffuseSum = lightColor;
+ AmbientSum = g_AmbientLightColor.rgb; // Default: ambient color is dark gray
+ DiffuseSum = vec4(lightColor.rgb, 1.0);
SpecularSum = vec3(0.0);
#endif
@@ -210,10 +137,22 @@ void main(){
#endif
#ifdef VERTEX_LIGHTING
- vertexLightValues = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
+ float spotFallOff = 1.0;
+ vec4 vLightDir;
+ lightComputeDir(wvPosition, lightColor.w, wvLightPos, vLightDir, lightVec);
+ #if __VERSION__ >= 110
+ // allow use of control flow
+ if(lightColor.w > 1.0){
+ #endif
+ spotFallOff = computeSpotFalloff(g_LightDirection, lightVec);
+ #if __VERSION__ >= 110
+ }
+ #endif
+
+ vertexLightValues = computeLighting(wvNormal, viewDir, vLightDir.xyz, vLightDir.w * spotFallOff, m_Shininess);
#endif
- #ifdef USE_REFLECTION
+ #ifdef USE_REFLECTION
computeRef(modelSpacePos);
#endif
}
\ No newline at end of file
diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag
new file mode 100644
index 000000000..09478c6e8
--- /dev/null
+++ b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag
@@ -0,0 +1,218 @@
+#import "Common/ShaderLib/Parallax.glsllib"
+#import "Common/ShaderLib/Optics.glsllib"
+#ifndef VERTEX_LIGHTING
+ #import "Common/ShaderLib/PhongLighting.glsllib"
+ #import "Common/ShaderLib/Lighting.glsllib"
+#endif
+
+varying vec2 texCoord;
+#ifdef SEPARATE_TEXCOORD
+ varying vec2 texCoord2;
+#endif
+
+varying vec3 AmbientSum;
+varying vec4 DiffuseSum;
+varying vec3 SpecularSum;
+
+#ifndef VERTEX_LIGHTING
+ uniform mat4 g_ViewMatrix;
+ uniform vec4 g_LightData[NB_LIGHTS];
+ varying vec3 vPos;
+#else
+ varying vec3 specularAccum;
+ varying vec4 diffuseAccum;
+#endif
+
+#ifdef DIFFUSEMAP
+ uniform sampler2D m_DiffuseMap;
+#endif
+
+#ifdef SPECULARMAP
+ uniform sampler2D m_SpecularMap;
+#endif
+
+#ifdef PARALLAXMAP
+ uniform sampler2D m_ParallaxMap;
+#endif
+#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
+ uniform float m_ParallaxHeight;
+#endif
+
+#ifdef LIGHTMAP
+ uniform sampler2D m_LightMap;
+#endif
+
+#ifdef NORMALMAP
+ uniform sampler2D m_NormalMap;
+ varying vec3 vTangent;
+ varying vec3 vBinormal;
+#endif
+varying vec3 vNormal;
+
+#ifdef ALPHAMAP
+ uniform sampler2D m_AlphaMap;
+#endif
+
+#ifdef COLORRAMP
+ uniform sampler2D m_ColorRamp;
+#endif
+
+uniform float m_AlphaDiscardThreshold;
+
+#ifndef VERTEX_LIGHTING
+uniform float m_Shininess;
+
+ #ifdef USE_REFLECTION
+ uniform float m_ReflectionPower;
+ uniform float m_ReflectionIntensity;
+ varying vec4 refVec;
+
+ uniform ENVMAP m_EnvMap;
+ #endif
+#endif
+
+void main(){
+ vec2 newTexCoord;
+
+ #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
+
+ #ifdef STEEP_PARALLAX
+ #ifdef NORMALMAP_PARALLAX
+ //parallax map is stored in the alpha channel of the normal map
+ newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
+ #else
+ //parallax map is a texture
+ newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
+ #endif
+ #else
+ #ifdef NORMALMAP_PARALLAX
+ //parallax map is stored in the alpha channel of the normal map
+ newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
+ #else
+ //parallax map is a texture
+ newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
+ #endif
+ #endif
+ #else
+ newTexCoord = texCoord;
+ #endif
+
+ #ifdef DIFFUSEMAP
+ vec4 diffuseColor = texture2D(m_DiffuseMap, newTexCoord);
+ #else
+ vec4 diffuseColor = vec4(1.0);
+ #endif
+
+ float alpha = DiffuseSum.a * diffuseColor.a;
+
+ #ifdef ALPHAMAP
+ alpha = alpha * texture2D(m_AlphaMap, newTexCoord).r;
+ #endif
+
+ #ifdef DISCARD_ALPHA
+ if(alpha < m_AlphaDiscardThreshold){
+ discard;
+ }
+ #endif
+
+ // ***********************
+ // Read from textures
+ // ***********************
+ #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
+ vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
+ //Note the -2.0 and -1.0. We invert the green channel of the normal map,
+ //as it's complient with normal maps generated with blender.
+ //see http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898
+ //for more explanation.
+ vec3 normal = normalize((normalHeight.xyz * vec3(2.0,-2.0,2.0) - vec3(1.0,-1.0,1.0)));
+ #elif !defined(VERTEX_LIGHTING)
+ vec3 normal = normalize(vNormal);
+ #endif
+
+ #ifdef SPECULARMAP
+ vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
+ #else
+ vec4 specularColor = vec4(1.0);
+ #endif
+
+ #ifdef LIGHTMAP
+ vec3 lightMapColor;
+ #ifdef SEPARATE_TEXCOORD
+ lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
+ #else
+ lightMapColor = texture2D(m_LightMap, texCoord).rgb;
+ #endif
+ specularColor.rgb *= lightMapColor;
+ diffuseColor.rgb *= lightMapColor;
+ #endif
+
+ #ifdef VERTEX_LIGHTING
+ gl_FragColor.rgb = AmbientSum * diffuseColor.rgb
+ +diffuseAccum.rgb *diffuseColor.rgb
+ +specularAccum.rgb * specularColor.rgb;
+ gl_FragColor.a=1.0;
+ #else
+
+ int i = 0;
+ gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;
+
+ #ifdef USE_REFLECTION
+ vec4 refColor = Optics_GetEnvColor(m_EnvMap, refVec.xyz);
+ #endif
+
+ #ifdef NORMALMAP
+ mat3 tbnMat = mat3(normalize(vTangent.xyz) , normalize(vBinormal.xyz) , normalize(vNormal.xyz));
+ #endif
+
+ for( int i = 0;i < NB_LIGHTS; i+=3){
+ vec4 lightColor = g_LightData[i];
+ vec4 lightData1 = g_LightData[i+1];
+ vec4 lightDir;
+ vec3 lightVec;
+ lightComputeDir(vPos, lightColor.w, lightData1, lightDir,lightVec);
+
+ float spotFallOff = 1.0;
+ #if __VERSION__ >= 110
+ // allow use of control flow
+ if(lightColor.w > 1.0){
+ #endif
+ spotFallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
+ #if __VERSION__ >= 110
+ }
+ #endif
+
+ #ifdef NORMALMAP
+ //Normal map -> lighting is computed in tangent space
+ lightDir.xyz = normalize(lightDir.xyz * tbnMat);
+ vec3 viewDir = normalize(-vPos.xyz * tbnMat);
+ #else
+ //no Normal map -> lighting is computed in view space
+ lightDir.xyz = normalize(lightDir.xyz);
+ vec3 viewDir = normalize(-vPos.xyz);
+ #endif
+
+ vec2 light = computeLighting(normal, viewDir, lightDir.xyz, lightDir.w * spotFallOff , m_Shininess);
+
+ #ifdef COLORRAMP
+ diffuseColor.rgb *= texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb;
+ specularColor.rgb *= texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb;
+ #endif
+
+ // Workaround, since it is not possible to modify varying variables
+ vec4 SpecularSum2 = vec4(SpecularSum, 1.0);
+ #ifdef USE_REFLECTION
+ // Interpolate light specularity toward reflection color
+ // Multiply result by specular map
+ specularColor = mix(SpecularSum2 * light.y, refColor, refVec.w) * specularColor;
+
+ SpecularSum2 = vec4(1.0);
+ light.y = 1.0;
+ #endif
+
+ gl_FragColor.rgb += DiffuseSum.rgb * lightColor.rgb * diffuseColor.rgb * vec3(light.x) +
+ SpecularSum2.rgb * specularColor.rgb * vec3(light.y);
+ }
+
+ #endif
+ gl_FragColor.a = alpha;
+}
diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert
new file mode 100644
index 000000000..81ea869b6
--- /dev/null
+++ b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert
@@ -0,0 +1,172 @@
+#import "Common/ShaderLib/Instancing.glsllib"
+#import "Common/ShaderLib/Skinning.glsllib"
+#import "Common/ShaderLib/Lighting.glsllib"
+#ifdef VERTEX_LIGHTING
+ #import "Common/ShaderLib/PhongLighting.glsllib"
+#endif
+
+
+uniform vec4 m_Ambient;
+uniform vec4 m_Diffuse;
+uniform vec4 m_Specular;
+uniform float m_Shininess;
+
+#if defined(VERTEX_LIGHTING)
+ uniform vec4 g_LightData[NB_LIGHTS];
+#endif
+uniform vec4 g_AmbientLightColor;
+varying vec2 texCoord;
+
+#ifdef SEPARATE_TEXCOORD
+ varying vec2 texCoord2;
+ attribute vec2 inTexCoord2;
+#endif
+
+varying vec3 AmbientSum;
+varying vec4 DiffuseSum;
+varying vec3 SpecularSum;
+
+attribute vec3 inPosition;
+attribute vec2 inTexCoord;
+attribute vec3 inNormal;
+
+#ifdef VERTEX_COLOR
+ attribute vec4 inColor;
+#endif
+
+#ifndef VERTEX_LIGHTING
+ varying vec3 vNormal;
+ varying vec3 vPos;
+ #ifdef NORMALMAP
+ attribute vec4 inTangent;
+ varying vec3 vTangent;
+ varying vec3 vBinormal;
+ #endif
+#else
+ varying vec3 specularAccum;
+ varying vec4 diffuseAccum;
+#endif
+
+#ifdef USE_REFLECTION
+ uniform vec3 g_CameraPosition;
+ uniform vec3 m_FresnelParams;
+ varying vec4 refVec;
+
+ /**
+ * Input:
+ * attribute inPosition
+ * attribute inNormal
+ * uniform g_WorldMatrix
+ * uniform g_CameraPosition
+ *
+ * Output:
+ * varying refVec
+ */
+ void computeRef(in vec4 modelSpacePos){
+ // vec3 worldPos = (g_WorldMatrix * modelSpacePos).xyz;
+ vec3 worldPos = TransformWorld(modelSpacePos).xyz;
+
+ vec3 I = normalize( g_CameraPosition - worldPos ).xyz;
+ // vec3 N = normalize( (g_WorldMatrix * vec4(inNormal, 0.0)).xyz );
+ vec3 N = normalize( TransformWorld(vec4(inNormal, 0.0)).xyz );
+
+ refVec.xyz = reflect(I, N);
+ refVec.w = m_FresnelParams.x + m_FresnelParams.y * pow(1.0 + dot(I, N), m_FresnelParams.z);
+ }
+#endif
+
+void main(){
+ vec4 modelSpacePos = vec4(inPosition, 1.0);
+ vec3 modelSpaceNorm = inNormal;
+
+ #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
+ vec3 modelSpaceTan = inTangent.xyz;
+ #endif
+
+ #ifdef NUM_BONES
+ #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
+ Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
+ #else
+ Skinning_Compute(modelSpacePos, modelSpaceNorm);
+ #endif
+ #endif
+
+ gl_Position = TransformWorldViewProjection(modelSpacePos);
+ texCoord = inTexCoord;
+ #ifdef SEPARATE_TEXCOORD
+ texCoord2 = inTexCoord2;
+ #endif
+
+ vec3 wvPosition = TransformWorldView(modelSpacePos).xyz;
+ vec3 wvNormal = normalize(TransformNormal(modelSpaceNorm));
+ vec3 viewDir = normalize(-wvPosition);
+
+
+ #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
+ vTangent = TransformNormal(modelSpaceTan);
+ vBinormal = cross(wvNormal, vTangent)* inTangent.w;
+ vNormal = wvNormal;
+ vPos = wvPosition;
+ #elif !defined(VERTEX_LIGHTING)
+ vNormal = wvNormal;
+ vPos = wvPosition;
+ #endif
+
+ #ifdef MATERIAL_COLORS
+ AmbientSum = m_Ambient.rgb * g_AmbientLightColor.rgb;
+ SpecularSum = m_Specular.rgb;
+ DiffuseSum = m_Diffuse;
+ #else
+ AmbientSum = g_AmbientLightColor.rgb;
+ SpecularSum = vec3(0.0);
+ DiffuseSum = vec4(1.0);
+ #endif
+ #ifdef VERTEX_COLOR
+ AmbientSum *= inColor.rgb;
+ DiffuseSum *= inColor;
+ #endif
+ #ifdef VERTEX_LIGHTING
+ int i = 0;
+ diffuseAccum = vec4(0.0);
+ specularAccum = vec3(0.0);
+ vec4 diffuseColor;
+ vec3 specularColor;
+ for (int i =0;i < NB_LIGHTS; i+=3){
+ vec4 lightColor = g_LightData[i];
+ vec4 lightData1 = g_LightData[i+1];
+ DiffuseSum = vec4(1.0);
+ #ifdef MATERIAL_COLORS
+ diffuseColor = m_Diffuse * vec4(lightColor.rgb, 1.0);
+ specularColor = m_Specular.rgb * lightColor.rgb;
+ #else
+ diffuseColor = vec4(lightColor.rgb, 1.0);
+ specularColor = vec3(0.0);
+ #endif
+
+ vec4 lightDir;
+ vec3 lightVec;
+ lightComputeDir(wvPosition, lightColor.w, lightData1, lightDir, lightVec);
+ // lightDir = normalize(lightDir);
+ // lightVec = normalize(lightVec);
+
+ float spotFallOff = 1.0;
+ #if __VERSION__ >= 110
+ // allow use of control flow
+ if(lightColor.w > 1.0){
+ #endif
+ vec4 lightDirection = g_LightData[i+2];
+ spotFallOff = computeSpotFalloff(lightDirection, lightVec);
+ #if __VERSION__ >= 110
+ }
+ #endif
+ vec2 v = computeLighting(wvNormal, viewDir, lightDir.xyz, lightDir.w * spotFallOff, m_Shininess);
+ diffuseAccum +=v.x * diffuseColor;
+ specularAccum += v.y * specularColor;
+ }
+ #endif
+
+
+ #ifdef USE_REFLECTION
+ computeRef(modelSpacePos);
+ #endif
+}
\ No newline at end of file
diff --git a/jme3-core/src/main/resources/Common/ShaderLib/Lighting.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/Lighting.glsllib
index 4d1b40436..3b8863b6c 100644
--- a/jme3-core/src/main/resources/Common/ShaderLib/Lighting.glsllib
+++ b/jme3-core/src/main/resources/Common/ShaderLib/Lighting.glsllib
@@ -1,48 +1,30 @@
-#ifndef NUM_LIGHTS
- #define NUM_LIGHTS 4
-#endif
+/*Common function for light calculations*/
-uniform mat4 g_ViewMatrix;
-uniform vec4 g_LightPosition[NUM_LIGHTS];
-uniform vec4 g_g_LightColor[NUM_LIGHTS];
-uniform float m_Shininess;
-float Lighting_Diffuse(vec3 norm, vec3 lightdir){
- return max(0.0, dot(norm, lightdir));
-}
-
-float Lighting_Specular(vec3 norm, vec3 viewdir, vec3 lightdir, float shiny){
- vec3 refdir = reflect(-lightdir, norm);
- return pow(max(dot(refdir, viewdir), 0.0), shiny);
-}
-
-void Lighting_Direction(vec3 worldPos, vec4 color, vec4 position, out vec4 lightDir){
- float posLight = step(0.5, color.w);
+/*
+* Computes light direction
+* lightType should be 0.0,1.0,2.0, repectively for Directional, point and spot lights.
+* Outputs the light direction and the light half vector.
+*/
+void lightComputeDir(in vec3 worldPos, in float ligthType, in vec4 position, out vec4 lightDir, out vec3 lightVec){
+ float posLight = step(0.5, ligthType);
vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
+ lightVec = tempVec;
float dist = length(tempVec);
-
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
- lightDir.xyz = tempVec / dist;
+ lightDir.xyz = tempVec / vec3(dist);
}
-void Lighting_ComputePS(vec3 tanNormal, mat3 tbnMat,
- int lightCount, out vec3 outDiffuse, out vec3 outSpecular){
- // find tangent view dir & vert pos
- vec3 tanViewDir = viewDir * tbnMat;
-
- for (int i = 0; i < lightCount; i++){
- // find light dir in tangent space, works for point & directional lights
- vec4 wvLightPos = (g_ViewMatrix * vec4(g_LightPosition[i].xyz, g_LightColor[i].w));
- wvLightPos.w = g_LightPosition[i].w;
-
- vec4 tanLightDir;
- Lighting_Direction(wvPosition, g_LightColor[i], wvLightPos, tanLightDir);
- tanLightDir.xyz = tanLightDir.xyz * tbnMat;
-
- vec3 lightScale = g_LightColor[i].rgb * tanLightDir.w;
- float specular = Lighting_Specular(tanNormal, tanViewDir, tanLightDir.xyz, m_Shininess);
- float diffuse = Lighting_Diffuse(tanNormal, tanLightDir.xyz);
- outSpecular += specular * lightScale * step(0.01, diffuse) * g_LightColor[i].rgb;
- outDiffuse += diffuse * lightScale * g_LightColor[i].rgb;
- }
+/*
+* Computes the spot falloff for a spotlight
+*/
+float computeSpotFalloff(in vec4 lightDirection, in vec3 lightVector){
+ vec3 L=normalize(lightVector);
+ vec3 spotdir = normalize(lightDirection.xyz);
+ float curAngleCos = dot(-L, spotdir);
+ float innerAngleCos = floor(lightDirection.w) * 0.001;
+ float outerAngleCos = fract(lightDirection.w);
+ float innerMinusOuter = innerAngleCos - outerAngleCos;
+ return clamp((curAngleCos - outerAngleCos) / innerMinusOuter, step(lightDirection.w, 0.001), 1.0);
}
+
diff --git a/jme3-core/src/main/resources/Common/ShaderLib/PhongLighting.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/PhongLighting.glsllib
new file mode 100644
index 000000000..8ebeb9924
--- /dev/null
+++ b/jme3-core/src/main/resources/Common/ShaderLib/PhongLighting.glsllib
@@ -0,0 +1,29 @@
+/*Standard Phong ligting*/
+
+/*
+* Computes diffuse factor
+*/
+float lightComputeDiffuse(in vec3 norm, in vec3 lightdir){
+ return max(0.0, dot(norm, lightdir));
+}
+
+/*
+* Computes specular factor
+*/
+float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
+ vec3 R = reflect(-lightdir, norm);
+ return pow(max(dot(R, viewdir), 0.0), shiny);
+}
+
+/*
+* Computes diffuse and specular factors and pack them in a vec2 (x=diffuse, y=specular)
+*/
+vec2 computeLighting(in vec3 norm, in vec3 viewDir, in vec3 lightDir, in float attenuation, in float shininess){
+ float diffuseFactor = lightComputeDiffuse(norm, lightDir);
+ float specularFactor = lightComputeSpecular(norm, viewDir, lightDir, shininess);
+ if (shininess <= 1.0) {
+ specularFactor = 0.0; // should be one instruction on most cards ..
+ }
+ specularFactor *= diffuseFactor;
+ return vec2(diffuseFactor, specularFactor) * vec2(attenuation);
+}
\ No newline at end of file
diff --git a/jme3-examples/src/main/java/jme3test/light/TestManyLightsSingle.java b/jme3-examples/src/main/java/jme3test/light/TestManyLightsSingle.java
new file mode 100644
index 000000000..acc0037b8
--- /dev/null
+++ b/jme3-examples/src/main/java/jme3test/light/TestManyLightsSingle.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * 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.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 COPYRIGHT OWNER OR
+ * CONTRIBUTORS 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.
+ */
+package jme3test.light;
+
+import com.jme3.app.BasicProfilerState;
+import com.jme3.app.SimpleApplication;
+import com.jme3.font.BitmapText;
+import com.jme3.input.KeyInput;
+import com.jme3.input.controls.ActionListener;
+import com.jme3.input.controls.KeyTrigger;
+import com.jme3.light.AmbientLight;
+import com.jme3.light.DirectionalLight;
+import com.jme3.light.Light;
+import com.jme3.light.LightList;
+import com.jme3.light.PointLight;
+import com.jme3.light.SpotLight;
+import com.jme3.material.Material;
+import com.jme3.material.TechniqueDef;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.FastMath;
+import com.jme3.math.Quaternion;
+import com.jme3.math.Vector3f;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.LightNode;
+import com.jme3.scene.Node;
+import com.jme3.scene.Spatial;
+import com.jme3.scene.control.AbstractControl;
+import com.jme3.scene.shape.Box;
+
+public class TestManyLightsSingle extends SimpleApplication {
+
+ public static void main(String[] args) {
+ TestManyLightsSingle app = new TestManyLightsSingle();
+ app.start();
+ }
+ TechniqueDef.LightMode lm = TechniqueDef.LightMode.MultiPass;
+ int lightNum = 6 ;
+
+ @Override
+ public void simpleInitApp() {
+ renderManager.setPreferredLightMode(lm);
+ renderManager.setSinglePassLightBatchSize(lightNum);
+
+
+ flyCam.setMoveSpeed(10);
+
+ Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
+ rootNode.attachChild(scene);
+ Node n = (Node) rootNode.getChild(0);
+ LightList lightList = n.getWorldLightList();
+ Geometry g = (Geometry) n.getChild("Grid-geom-1");
+
+ g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
+
+ /* A colored lit cube. Needs light source! */
+ Box boxMesh = new Box(1f, 1f, 1f);
+ Geometry boxGeo = new Geometry("Colored Box", boxMesh);
+ Material boxMat = g.getMaterial().clone();
+ boxMat.setBoolean("UseMaterialColors", true);
+ boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
+ boxMat.setColor("Diffuse", ColorRGBA.Blue);
+ boxGeo.setMaterial(boxMat);
+
+ int nb = 0;
+ for (Light light : lightList) {
+ nb++;
+ PointLight p = (PointLight) light;
+ if (nb >60) {
+ n.removeLight(light);
+ } else {
+
+ LightNode ln = new LightNode("l", light);
+ n.attachChild(ln);
+ ln.setLocalTranslation(p.getPosition());
+ int rand = FastMath.nextRandomInt(0, 3);
+ switch (rand) {
+ case 0:
+ light.setColor(ColorRGBA.Red);
+ // ln.addControl(new MoveControl(5f));
+ break;
+ case 1:
+ light.setColor(ColorRGBA.Yellow);
+ // ln.addControl(new MoveControl(5f));
+ break;
+ case 2:
+ light.setColor(ColorRGBA.Green);
+ //ln.addControl(new MoveControl(-5f));
+ break;
+ case 3:
+ light.setColor(ColorRGBA.Orange);
+ //ln.addControl(new MoveControl(-5f));
+ break;
+ }
+ }
+ Geometry b = boxGeo.clone();
+ n.attachChild(b);
+ b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
+
+ }
+
+
+// cam.setLocation(new Vector3f(3.1893547f, 17.977385f, 30.8378f));
+// cam.setRotation(new Quaternion(0.14317635f, 0.82302624f, -0.23777823f, 0.49557027f));
+
+ cam.setLocation(new Vector3f(-1.8901939f, 29.34097f, 73.07533f));
+ cam.setRotation(new Quaternion(0.0021000702f, 0.971012f, -0.23886925f, 0.008527749f));
+
+
+ BasicProfilerState profiler = new BasicProfilerState(true);
+ profiler.setGraphScale(1000f);
+
+ // getStateManager().attach(profiler);
+// guiNode.setCullHint(CullHint.Always);
+
+
+
+
+ flyCam.setDragToRotate(true);
+ flyCam.setMoveSpeed(50);
+
+
+ inputManager.addListener(new ActionListener() {
+ public void onAction(String name, boolean isPressed, float tpf) {
+ if (name.equals("toggle") && isPressed) {
+ if (lm == TechniqueDef.LightMode.SinglePass) {
+ lm = TechniqueDef.LightMode.MultiPass;
+ } else {
+ lm = TechniqueDef.LightMode.SinglePass;
+ }
+ renderManager.setPreferredLightMode(lm);
+ }
+ if (name.equals("lightsUp") && isPressed) {
+ lightNum++;
+ renderManager.setSinglePassLightBatchSize(lightNum);
+ helloText.setText("nb lights per batch : " + lightNum);
+ }
+ if (name.equals("lightsDown") && isPressed) {
+ lightNum--;
+ renderManager.setSinglePassLightBatchSize(lightNum);
+ helloText.setText("nb lights per batch : " + lightNum);
+ }
+ }
+ }, "toggle", "lightsUp", "lightsDown");
+
+ inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
+ inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
+ inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
+
+
+ SpotLight spot = new SpotLight();
+ spot.setDirection(new Vector3f(-1f, -1f, -1f).normalizeLocal());
+ spot.setColor(ColorRGBA.Blue.mult(5));
+ spot.setSpotOuterAngle(FastMath.DEG_TO_RAD * 20);
+ spot.setSpotInnerAngle(FastMath.DEG_TO_RAD * 5);
+ spot.setPosition(new Vector3f(10, 10, 20));
+ rootNode.addLight(spot);
+
+ DirectionalLight dl = new DirectionalLight();
+ dl.setDirection(new Vector3f(-1, -1, 1));
+ rootNode.addLight(dl);
+
+ AmbientLight al = new AmbientLight();
+ al.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
+ rootNode.addLight(al);
+
+
+ /**
+ * Write text on the screen (HUD)
+ */
+ guiNode.detachAllChildren();
+ guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
+ helloText = new BitmapText(guiFont, false);
+ helloText.setSize(guiFont.getCharSet().getRenderedSize());
+ helloText.setText("nb lights per batch : " + lightNum);
+ helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
+ guiNode.attachChild(helloText);
+
+
+ }
+ BitmapText helloText;
+ long time;
+ long nbFrames;
+ long startTime = 0;
+
+ @Override
+ public void simpleUpdate(float tpf) {
+// if (nbFrames == 4000) {
+// startTime = System.nanoTime();
+// }
+// if (nbFrames > 4000) {
+// time = System.nanoTime();
+// float average = ((float) time - (float) startTime) / ((float) nbFrames - 4000f);
+// helloText.setText("Average = " + average);
+// }
+// nbFrames++;
+ }
+
+ class MoveControl extends AbstractControl {
+
+ float direction;
+ Vector3f origPos = new Vector3f();
+
+ public MoveControl(float direction) {
+ this.direction = direction;
+ }
+
+ @Override
+ public void setSpatial(Spatial spatial) {
+ super.setSpatial(spatial); //To change body of generated methods, choose Tools | Templates.
+ origPos.set(spatial.getLocalTranslation());
+ }
+ float time = 0;
+
+ @Override
+ protected void controlUpdate(float tpf) {
+ time += tpf;
+ spatial.setLocalTranslation(origPos.x + FastMath.cos(time) * direction, origPos.y, origPos.z + FastMath.sin(time) * direction);
+ }
+
+ @Override
+ protected void controlRender(RenderManager rm, ViewPort vp) {
+ }
+ }
+}
\ No newline at end of file
diff --git a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java
index 4909b393e..af42dd5ee 100644
--- a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java
+++ b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java
@@ -802,7 +802,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
TextureUtil.uploadTexture(img, target, i, 0, tdc);
}
} else {*/
- TextureUtil.uploadTexture(ctxCaps, img, target, 0, 0, false);
+ TextureUtil.uploadTexture(caps, img, target, 0, 0, false);
//}
img.clearUpdateNeeded();
@@ -853,7 +853,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
public void modifyTexture(Texture tex, Image pixels, int x, int y) {
setTexture(0, tex);
- TextureUtil.uploadSubTexture(ctxCaps, pixels, convertTextureType(tex.getType()), 0, x, y, false);
+ TextureUtil.uploadSubTexture(caps, pixels, convertTextureType(tex.getType()), 0, x, y, false);
}
private void clearTextureUnits() {
diff --git a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java
index fc0a1c294..6caeb4a88 100644
--- a/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java
+++ b/jme3-lwjgl/src/main/java/com/jme3/renderer/lwjgl/LwjglRenderer.java
@@ -57,7 +57,9 @@ import com.jme3.util.BufferUtils;
import com.jme3.util.ListMap;
import com.jme3.util.NativeObjectManager;
import java.nio.*;
+import java.util.ArrayList;
import java.util.EnumSet;
+import java.util.HashSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -70,7 +72,6 @@ import static org.lwjgl.opengl.ARBInstancedArrays.*;
import static org.lwjgl.opengl.ARBMultisample.*;
import static org.lwjgl.opengl.ARBTextureMultisample.*;
import static org.lwjgl.opengl.ARBVertexArrayObject.*;
-import org.lwjgl.opengl.ContextCapabilities;
import static org.lwjgl.opengl.EXTFramebufferBlit.*;
import static org.lwjgl.opengl.EXTFramebufferMultisample.*;
import static org.lwjgl.opengl.EXTFramebufferObject.*;
@@ -84,7 +85,7 @@ import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.opengl.GL14.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
-import org.lwjgl.opengl.GLContext;
+import org.lwjgl.opengl.GL30;
//import static org.lwjgl.opengl.GL21.*;
//import static org.lwjgl.opengl.GL30.*;
@@ -101,10 +102,7 @@ public class LwjglRenderer implements Renderer {
private final RenderContext context = new RenderContext();
private final NativeObjectManager objManager = new NativeObjectManager();
private final EnumSet