aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core-data/Common/MatDefs
diff options
context:
space:
mode:
authorScott Barta <sbarta@google.com>2012-03-01 12:35:35 -0800
committerScott Barta <sbarta@google.com>2012-03-01 12:40:08 -0800
commit59b2e6871c65f58fdad78cd7229c292f6a177578 (patch)
tree2d4e7bfc05b93f40b34675d77e403dd1c25efafd /engine/src/core-data/Common/MatDefs
parentf9b30489e75ac1eabc365064959804e99534f7ab (diff)
downloadjmonkeyengine-59b2e6871c65f58fdad78cd7229c292f6a177578.tar.gz
Adds the jMonkeyEngine library to the build.
Adds the jMonkeyEngine open source 3D game engine to the build. This is built as a static library and is only used by the Finsky client. Change-Id: I06a3f054df7b8a67757267d884854f70c5a16ca0
Diffstat (limited to 'engine/src/core-data/Common/MatDefs')
-rw-r--r--engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.frag24
-rw-r--r--engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.j3md21
-rw-r--r--engine/src/core-data/Common/MatDefs/Blur/RadialBlur.frag47
-rw-r--r--engine/src/core-data/Common/MatDefs/Blur/RadialBlur.j3md36
-rw-r--r--engine/src/core-data/Common/MatDefs/Blur/RadialBlur15.frag50
-rw-r--r--engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.frag25
-rw-r--r--engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.j3md21
-rw-r--r--engine/src/core-data/Common/MatDefs/Gui/Gui.frag16
-rw-r--r--engine/src/core-data/Common/MatDefs/Gui/Gui.j3md26
-rw-r--r--engine/src/core-data/Common/MatDefs/Gui/Gui.vert29
-rw-r--r--engine/src/core-data/Common/MatDefs/Hdr/LogLum.frag65
-rw-r--r--engine/src/core-data/Common/MatDefs/Hdr/LogLum.j3md31
-rw-r--r--engine/src/core-data/Common/MatDefs/Hdr/ToneMap.frag31
-rw-r--r--engine/src/core-data/Common/MatDefs/Hdr/ToneMap.j3md23
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/Deferred.frag146
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/Deferred.j3md61
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/Deferred.vert10
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/GBuf.frag86
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/GBuf.vert71
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/Glow.frag32
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/Lighting.frag278
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/Lighting.j3md238
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/Lighting.vert207
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.frag9
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.j3md20
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.vert11
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Particle.frag22
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Particle.j3md89
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Particle.vert42
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/ShowNormals.frag5
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/ShowNormals.j3md10
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/ShowNormals.vert11
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.frag27
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.j3md32
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.vert11
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Sky.frag11
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Sky.j3md27
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Sky.vert25
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/SolidColor.j3md44
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Unshaded.frag50
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md70
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Unshaded.vert37
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/VertexColor.j3md18
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/WireColor.j3md38
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PostShadow.frag12
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md26
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert31
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag119
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md63
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert37
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag139
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag15
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PreShadow.j3md19
-rw-r--r--engine/src/core-data/Common/MatDefs/Shadow/PreShadow.vert12
54 files changed, 2656 insertions, 0 deletions
diff --git a/engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.frag b/engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.frag
new file mode 100644
index 0000000..35ba78b
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.frag
@@ -0,0 +1,24 @@
+uniform sampler2D m_Texture; // this should hold the texture rendered by the horizontal blur pass
+uniform float m_Size;
+uniform float m_Scale;
+
+varying vec2 texCoord;
+
+void main(){
+ float blurSize = m_Scale/m_Size;
+ vec4 sum = vec4(0.0);
+
+ // blur in x (vertical)
+ // take nine samples, with the distance blurSize between them
+ sum += texture2D(m_Texture, vec2(texCoord.x- 4.0*blurSize, texCoord.y )) * 0.05;
+ sum += texture2D(m_Texture, vec2(texCoord.x- 3.0*blurSize, texCoord.y )) * 0.09;
+ sum += texture2D(m_Texture, vec2(texCoord.x - 2.0*blurSize, texCoord.y)) * 0.12;
+ sum += texture2D(m_Texture, vec2(texCoord.x- blurSize, texCoord.y )) * 0.15;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y)) * 0.16;
+ sum += texture2D(m_Texture, vec2(texCoord.x+ blurSize, texCoord.y )) * 0.15;
+ sum += texture2D(m_Texture, vec2(texCoord.x+ 2.0*blurSize, texCoord.y )) * 0.12;
+ sum += texture2D(m_Texture, vec2(texCoord.x+ 3.0*blurSize, texCoord.y )) * 0.09;
+ sum += texture2D(m_Texture, vec2(texCoord.x+ 4.0*blurSize, texCoord.y )) * 0.05;
+
+ gl_FragColor = sum;
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.j3md b/engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.j3md
new file mode 100644
index 0000000..ddb262e
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Blur/HGaussianBlur.j3md
@@ -0,0 +1,21 @@
+MaterialDef Bloom {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Float Size
+ Float Scale
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Blur/HGaussianBlur.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Blur/RadialBlur.frag b/engine/src/core-data/Common/MatDefs/Blur/RadialBlur.frag
new file mode 100644
index 0000000..b3adfd4
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Blur/RadialBlur.frag
@@ -0,0 +1,47 @@
+uniform sampler2D m_Texture;
+uniform float m_SampleDist;
+uniform float m_SampleStrength;
+uniform float m_Samples[10];
+varying vec2 texCoord;
+
+void main(void)
+{
+ // some sample positions
+ //float samples[10] = float[](-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08);
+
+ // 0.5,0.5 is the center of the screen
+ // so substracting texCoord from it will result in
+ // a vector pointing to the middle of the screen
+ vec2 dir = 0.5 - texCoord;
+
+ // calculate the distance to the center of the screen
+ float dist = sqrt(dir.x*dir.x + dir.y*dir.y);
+
+ // normalize the direction (reuse the distance)
+ dir = dir/dist;
+
+ // this is the original colour of this fragment
+ // using only this would result in a nonblurred version
+ vec4 colorRes = texture2D(m_Texture,texCoord);
+
+ vec4 sum = colorRes;
+
+ // take 10 additional blur samples in the direction towards
+ // the center of the screen
+ for (int i = 0; i < 10; i++)
+ {
+ sum += texture2D( m_Texture, texCoord + dir * m_Samples[i] * m_SampleDist );
+ }
+
+ // we have taken eleven samples
+ sum *= 1.0/11.0;
+
+ // weighten the blur effect with the distance to the
+ // center of the screen ( further out is blurred more)
+ float t = dist * m_SampleStrength;
+ t = clamp( t ,0.0,1.0); //0 &lt;= t &lt;= 1
+
+ //Blend the original color with the averaged pixels
+ gl_FragColor =mix( colorRes, sum, t );
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Blur/RadialBlur.j3md b/engine/src/core-data/Common/MatDefs/Blur/RadialBlur.j3md
new file mode 100644
index 0000000..1e397fa
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Blur/RadialBlur.j3md
@@ -0,0 +1,36 @@
+MaterialDef Radial Blur {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Color Color
+ Float SampleDist
+ Float SampleStrength
+ FloatArray Samples
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Blur/RadialBlur15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ }
+ }
+
+ Technique {
+ VertexShader GLSL120: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL120: Common/MatDefs/Blur/RadialBlur.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Blur/RadialBlur15.frag b/engine/src/core-data/Common/MatDefs/Blur/RadialBlur15.frag
new file mode 100644
index 0000000..cc40350
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Blur/RadialBlur15.frag
@@ -0,0 +1,50 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+uniform float m_SampleDist;
+uniform float m_SampleStrength;
+uniform float m_Samples[10];
+
+in vec2 texCoord;
+out vec4 outFragColor;
+
+void main(void)
+{
+ // some sample positions
+ //float samples[10] = float[](-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08);
+
+ // 0.5,0.5 is the center of the screen
+ // so substracting texCoord from it will result in
+ // a vector pointing to the middle of the screen
+ vec2 dir = 0.5 - texCoord;
+
+ // calculate the distance to the center of the screen
+ float dist = sqrt(dir.x*dir.x + dir.y*dir.y);
+
+ // normalize the direction (reuse the distance)
+ dir = dir/dist;
+
+ // this is the original colour of this fragment
+ // using only this would result in a nonblurred version
+ vec4 colorRes = getColor(m_Texture,texCoord);
+
+ vec4 sum = colorRes;
+
+ // take 10 additional blur samples in the direction towards
+ // the center of the screen
+ for (int i = 0; i < 10; i++){
+ sum += getColor( m_Texture, texCoord + dir * m_Samples[i] * m_SampleDist );
+ }
+
+ // we have taken eleven samples
+ sum *= 1.0/11.0;
+
+ // weighten the blur effect with the distance to the
+ // center of the screen ( further out is blurred more)
+ float t = dist * m_SampleStrength;
+ t = clamp( t ,0.0,1.0); //0 &lt;= t &lt;= 1
+
+ //Blend the original color with the averaged pixels
+ outFragColor =mix( colorRes, sum, t );
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.frag b/engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.frag
new file mode 100644
index 0000000..3e20fe5
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.frag
@@ -0,0 +1,25 @@
+uniform sampler2D m_Texture; // this should hold the texture rendered by the horizontal blur pass
+uniform float m_Size;
+uniform float m_Scale;
+varying vec2 texCoord;
+
+
+
+void main(void)
+{ float blurSize = m_Scale/m_Size;
+ vec4 sum = vec4(0.0);
+
+ // blur in y (vertical)
+ // take nine samples, with the distance blurSize between them
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y - 4.0*blurSize)) * 0.05;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y - 3.0*blurSize)) * 0.09;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y - 2.0*blurSize)) * 0.12;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y - blurSize)) * 0.15;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y)) * 0.16;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y + blurSize)) * 0.15;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y + 2.0*blurSize)) * 0.12;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y + 3.0*blurSize)) * 0.09;
+ sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y + 4.0*blurSize)) * 0.05;
+
+ gl_FragColor = sum;
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.j3md b/engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.j3md
new file mode 100644
index 0000000..163f9f3
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Blur/VGaussianBlur.j3md
@@ -0,0 +1,21 @@
+MaterialDef Bloom {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Float Size
+ Float Scale
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Blur/VGaussianBlur.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Gui/Gui.frag b/engine/src/core-data/Common/MatDefs/Gui/Gui.frag
new file mode 100644
index 0000000..caa666c
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Gui/Gui.frag
@@ -0,0 +1,16 @@
+#ifdef TEXTURE
+uniform sampler2D m_Texture;
+varying vec2 texCoord;
+#endif
+
+varying vec4 color;
+
+void main() {
+ #ifdef TEXTURE
+ vec4 texVal = texture2D(m_Texture, texCoord);
+ gl_FragColor = texVal * color;
+ #else
+ gl_FragColor = color;
+ #endif
+}
+
diff --git a/engine/src/core-data/Common/MatDefs/Gui/Gui.j3md b/engine/src/core-data/Common/MatDefs/Gui/Gui.j3md
new file mode 100644
index 0000000..ea871b5
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Gui/Gui.j3md
@@ -0,0 +1,26 @@
+MaterialDef Default GUI {
+
+ MaterialParameters {
+ Texture2D Texture
+ Color Color ( Color )
+ Boolean VertexColor
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Gui/Gui.vert
+ FragmentShader GLSL100: Common/MatDefs/Gui/Gui.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ TEXTURE : Texture
+ VERTEX_COLOR : VertexColor
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Gui/Gui.vert b/engine/src/core-data/Common/MatDefs/Gui/Gui.vert
new file mode 100644
index 0000000..0591c5e
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Gui/Gui.vert
@@ -0,0 +1,29 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform vec4 m_Color;
+
+attribute vec3 inPosition;
+
+#ifdef VERTEX_COLOR
+attribute vec4 inColor;
+#endif
+
+#ifdef TEXTURE
+attribute vec2 inTexCoord;
+varying vec2 texCoord;
+#endif
+
+varying vec4 color;
+
+void main() {
+ //vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
+ //gl_Position = vec4(pos, 0.0, 1.0);
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
+ #ifdef TEXTURE
+ texCoord = inTexCoord;
+ #endif
+ #ifdef VERTEX_COLOR
+ color = m_Color * inColor;
+ #else
+ color = m_Color;
+ #endif
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Hdr/LogLum.frag b/engine/src/core-data/Common/MatDefs/Hdr/LogLum.frag
new file mode 100644
index 0000000..68f08e9
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Hdr/LogLum.frag
@@ -0,0 +1,65 @@
+#import "Common/ShaderLib/Hdr.glsllib"
+
+uniform sampler2D m_Texture;
+varying vec2 texCoord;
+
+#ifdef BLOCKS
+ uniform vec2 m_PixelSize;
+ uniform vec2 m_BlockSize;
+ uniform float m_NumPixels;
+#endif
+
+vec4 blocks(vec2 halfBlockSize, vec2 pixelSize, float numPixels){
+ vec2 startUV = texCoord - halfBlockSize;
+ vec2 endUV = texCoord + halfBlockSize;
+
+ vec4 sum = vec4(0.0);
+ float numPix = 0.0;
+ //float maxLum = 0.0;
+
+ for (float x = startUV.x; x < endUV.x; x += pixelSize.x){
+ for (float y = startUV.y; y < endUV.y; y += pixelSize.y){
+ numPix += 1.0;
+ vec4 color = texture2D(m_Texture, vec2(x,y));
+
+ #ifdef ENCODE_LUM
+ color = HDR_EncodeLum(HDR_GetLum(color.rgb));
+ #endif
+ //#ifdef COMPUTE_MAX
+ //maxLum = max(color.r, maxLum);
+ //#endif
+ sum += color;
+ }
+ }
+ sum /= numPix;
+
+ #ifdef DECODE_LUM
+ sum = vec4(HDR_DecodeLum(sum));
+ //#ifdef COMPUTE_MAX
+ //maxLum = HDR_GetExpLum(maxLum);
+ //#endif
+ #endif
+
+ return sum;
+}
+
+vec4 fetch(){
+ vec4 color = texture2D(m_Texture, texCoord);
+ #ifdef ENCODE_LUM
+ return HDR_EncodeLum(HDR_GetLum(color.rgb));
+ #elif defined DECODE_LUM
+ return vec4(HDR_DecodeLum(color));
+ #else
+ return color;
+ #endif
+}
+
+void main() {
+ #ifdef BLOCKS
+ gl_FragColor = blocks(m_BlockSize * vec2(0.5), m_PixelSize, m_NumPixels);
+ #else
+ gl_FragColor = vec4(fetch());
+ #endif
+}
+
+
diff --git a/engine/src/core-data/Common/MatDefs/Hdr/LogLum.j3md b/engine/src/core-data/Common/MatDefs/Hdr/LogLum.j3md
new file mode 100644
index 0000000..0c4c6c8
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Hdr/LogLum.j3md
@@ -0,0 +1,31 @@
+MaterialDef Log Lum 2D {
+
+ MaterialParameters {
+ Texture2D Texture
+ Vector2 BlockSize
+ Vector2 PixelSize
+ Float NumPixels
+ Boolean DecodeLum
+ Boolean EncodeLum
+ Boolean Blocks
+ Boolean ComputeMax
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Gui/Gui.vert
+ FragmentShader GLSL100: Common/MatDefs/Hdr/LogLum.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ TEXTURE
+ ENCODE_LUM : EncodeLum
+ DECODE_LUM : DecodeLum
+ BLOCKS : Blocks
+ COMPUTE_MAX : ComputeMax
+ }
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Hdr/ToneMap.frag b/engine/src/core-data/Common/MatDefs/Hdr/ToneMap.frag
new file mode 100644
index 0000000..f221030
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Hdr/ToneMap.frag
@@ -0,0 +1,31 @@
+#import "Common/ShaderLib/Hdr.glsllib"
+
+varying vec2 texCoord;
+
+uniform sampler2D m_Texture;
+uniform sampler2D m_Lum;
+uniform sampler2D m_Lum2;
+
+uniform float m_A;
+uniform float m_White;
+uniform float m_BlendFactor;
+uniform float m_Gamma;
+
+void main() {
+ float avgLumA = HDR_DecodeLum( texture2D(m_Lum, vec2(0.0)) );
+ float avgLumB = HDR_DecodeLum( texture2D(m_Lum2, vec2(0.0)) );
+ float lerpedLum = mix(avgLumA, avgLumB, m_BlendFactor);
+
+ vec4 color = texture2D(m_Texture, texCoord);
+ vec3 c1 = HDR_ToneMap(color.rgb, lerpedLum, m_A, m_White);
+ //vec3 c2 = HDR_ToneMap2(color.rgb, lerpedLum, m_A * vec2(0.25), m_White);
+
+ //float l1 = HDR_GetLuminance(c1);
+ //float l2 = HDR_GetLuminance(c2);
+
+ //vec3 final = mix(c2, c1, clamp(l1, 0.0, 1.0));
+
+ //tonedColor = pow(tonedColor, vec3(m_Gamma));
+ gl_FragColor = vec4(c1, color.a);
+}
+
diff --git a/engine/src/core-data/Common/MatDefs/Hdr/ToneMap.j3md b/engine/src/core-data/Common/MatDefs/Hdr/ToneMap.j3md
new file mode 100644
index 0000000..24fbd04
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Hdr/ToneMap.j3md
@@ -0,0 +1,23 @@
+MaterialDef Tone Mapper {
+ MaterialParameters {
+ Texture2D Texture
+ Texture2D Lum
+ Texture2D Lum2
+ Float BlendFactor
+ Float White
+ Float A
+ Float Gamma
+ }
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Gui/Gui.vert
+ FragmentShader GLSL100: Common/MatDefs/Hdr/ToneMap.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ TEXTURE
+ }
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Light/Deferred.frag b/engine/src/core-data/Common/MatDefs/Light/Deferred.frag
new file mode 100644
index 0000000..9fc7ebb
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/Deferred.frag
@@ -0,0 +1,146 @@
+#define ATTENUATION
+//#define HQ_ATTENUATION
+
+varying vec2 texCoord;
+
+uniform sampler2D m_DiffuseData;
+uniform sampler2D m_SpecularData;
+uniform sampler2D m_NormalData;
+uniform sampler2D m_DepthData;
+
+uniform vec3 m_FrustumCorner;
+uniform vec2 m_FrustumNearFar;
+
+uniform vec4 g_LightColor;
+uniform vec4 g_LightPosition;
+uniform vec3 g_CameraPosition;
+
+uniform mat4 m_ViewProjectionMatrixInverse;
+
+#ifdef COLORRAMP
+ uniform sampler2D m_ColorRamp;
+#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){
+//#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(dot(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 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec4 wvLightDir, in float shiny){
+ float diffuseFactor = lightComputeDiffuse(wvNorm, wvLightDir.xyz, wvViewDir);
+ float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir.xyz, shiny);
+ return vec2(diffuseFactor, specularFactor) * vec2(wvLightDir.w);
+}
+
+vec3 decodeNormal(in vec4 enc){
+ vec4 nn = enc * vec4(2.0,2.0,0.0,0.0) + vec4(-1.0,-1.0,1.0,-1.0);
+ float l = dot(nn.xyz, -nn.xyw);
+ nn.z = l;
+ nn.xy *= sqrt(l);
+ return nn.xyz * vec3(2.0) + vec3(0.0,0.0,-1.0);
+}
+
+vec3 getPosition(in vec2 newTexCoord){
+ //Reconstruction from depth
+ float depth = texture2D(m_DepthData, newTexCoord).r;
+ //if (depth == 1.0)
+ // return vec3(0.0, 0.0, 2.0);
+ //depth = (2.0 * m_FrustumNearFar.x)
+ /// (m_FrustumNearFar.y + m_FrustumNearFar.x - depth * (m_FrustumNearFar.y-m_FrustumNearFar.x));
+
+ //one frustum corner method
+ //float x = mix(-m_FrustumCorner.x, m_FrustumCorner.x, newTexCoord.x);
+ //float y = mix(-m_FrustumCorner.y, m_FrustumCorner.y, newTexCoord.y);
+
+ //return depth * vec3(x, y, m_FrustumCorner.z);
+ vec4 pos;
+ pos.xy = (newTexCoord * vec2(2.0)) - vec2(1.0);
+ pos.z = depth;
+ pos.w = 1.0;
+ pos = m_ViewProjectionMatrixInverse * pos;
+ //pos /= pos.w;
+ return pos.xyz;
+}
+
+// JME3 lights in world space
+void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
+ #ifdef DIR_LIGHT
+ lightDir.xyz = -position.xyz;
+ #else
+ lightDir.xyz = position.xyz - worldPos.xyz;
+ float dist = length(lightDir.xyz);
+ lightDir.w = clamp(1.0 - position.w * dist, 0.0, 1.0);
+ lightDir.xyz /= dist;
+ #endif
+
+/*
+ float posLight = step(0.5, color.w);
+ vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
+ #ifdef ATTENUATION
+ float dist = length(tempVec);
+ lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
+ lightDir.xyz = tempVec / vec3(dist);
+ #ifdef HQ_ATTENUATION
+ lightVec = tempVec;
+ #endif
+ #else
+ lightDir = vec4(normalize(tempVec), 1.0);
+ #endif
+*/
+}
+
+void main(){
+ vec2 newTexCoord = texCoord;
+ vec4 diffuseColor = texture2D(m_DiffuseData, newTexCoord);
+ if (diffuseColor.a == 0.0)
+ discard;
+
+ vec4 specularColor = texture2D(m_SpecularData, newTexCoord);
+ vec3 worldPosition = getPosition(newTexCoord);
+ vec3 viewDir = normalize(g_CameraPosition - worldPosition);
+
+ vec4 normalInfo = vec4(texture2D(m_NormalData, newTexCoord).rg, 0.0, 0.0);
+ vec3 normal = decodeNormal(normalInfo);
+
+ vec4 lightDir;
+ lightComputeDir(worldPosition, g_LightColor, g_LightPosition, lightDir);
+
+ vec2 light = computeLighting(worldPosition, normal, viewDir, lightDir, specularColor.w*128.0);
+
+ #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
+
+ gl_FragColor = vec4(light.x * diffuseColor.xyz + light.y * specularColor.xyz, 1.0);
+ gl_FragColor.xyz *= g_LightColor.xyz;
+}
diff --git a/engine/src/core-data/Common/MatDefs/Light/Deferred.j3md b/engine/src/core-data/Common/MatDefs/Light/Deferred.j3md
new file mode 100644
index 0000000..c386a61
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/Deferred.j3md
@@ -0,0 +1,61 @@
+MaterialDef Phong Lighting Deferred {
+
+ MaterialParameters {
+
+ // Use more efficent algorithms to improve performance
+ Boolean LowQuality
+
+ // Improve quality at the cost of performance
+ Boolean HighQuality
+
+ // 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
+
+ Texture2D DiffuseData
+ Texture2D SpecularData
+ Texture2D NormalData
+ Texture2D DepthData
+
+ Vector3 FrustumCorner
+ Vector2 FrustumNearFar
+ Matrix4 ViewProjectionMatrixInverse
+
+ // Color ramp, will map diffuse and specular values through it.
+ Texture2D ColorRamp
+ }
+
+ Technique {
+ LightMode MultiPass
+
+ VertexShader GLSL100: Common/MatDefs/Light/Deferred.vert
+ FragmentShader GLSL100: Common/MatDefs/Light/Deferred.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ ViewMatrix
+ CameraPosition
+ }
+
+ Defines {
+ ATTENUATION : Attenuation
+ V_TANGENT : VTangent
+ MINNAERT : Minnaert
+ WARDISO : WardIso
+ LOW_QUALITY : LowQuality
+ HQ_ATTENUATION : HighQuality
+ COLORRAMP : ColorRamp
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Light/Deferred.vert b/engine/src/core-data/Common/MatDefs/Light/Deferred.vert
new file mode 100644
index 0000000..0743cc1
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/Deferred.vert
@@ -0,0 +1,10 @@
+varying vec2 texCoord;
+
+attribute vec3 inPosition;
+attribute vec2 inTexCoord;
+
+void main(){
+ texCoord = inTexCoord;
+ vec4 pos = vec4(inPosition, 1.0);
+ gl_Position = vec4(sign(pos.xy-vec2(0.5)), 0.0, 1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Light/GBuf.frag b/engine/src/core-data/Common/MatDefs/Light/GBuf.frag
new file mode 100644
index 0000000..3970624
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/GBuf.frag
@@ -0,0 +1,86 @@
+#import "Common/ShaderLib/Optics.glsllib"
+
+uniform float m_Shininess;
+
+varying vec2 texCoord;
+varying vec4 AmbientSum;
+varying vec4 DiffuseSum;
+varying vec4 SpecularSum;
+
+varying float vDepth;
+varying vec3 vNormal;
+
+#ifdef DIFFUSEMAP
+ uniform sampler2D m_DiffuseMap;
+#endif
+
+#ifdef SPECULARMAP
+ uniform sampler2D m_SpecularMap;
+#endif
+
+#ifdef PARALLAXMAP
+ uniform sampler2D m_ParallaxMap;
+#endif
+
+#ifdef NORMALMAP
+ uniform sampler2D m_NormalMap;
+ varying mat3 tbnMat;
+#endif
+
+vec2 encodeNormal(in vec3 n){
+ vec2 enc = normalize(n.xy) * (sqrt(-n.z*0.5+0.5));
+ enc = enc*vec2(0.5)+vec2(0.5);
+ return enc;
+}
+
+void main(){
+ vec2 newTexCoord = texCoord;
+ float height = 0.0;
+ #if defined(PARALLAXMAP) || defined(NORMALMAP_PARALLAX)
+ #ifdef PARALLAXMAP
+ height = texture2D(m_ParallaxMap, texCoord).r;
+ #else
+ height = texture2D(m_NormalMap, texCoord).a;
+ #endif
+ float heightScale = 0.05;
+ float heightBias = heightScale * -0.5;
+ height = (height * heightScale + heightBias);
+ #endif
+
+
+ // ***********************
+ // Read from textures
+ // ***********************
+ #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
+ vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
+ vec3 normal = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
+ normal.y = -normal.y;
+
+ normal = tbnMat * normal;
+ #else
+ vec3 normal = vNormal;
+ #if !defined(LOW_QUALITY) && !defined(V_TANGENT)
+ normal = normalize(normal);
+ #endif
+ #endif
+
+ #ifdef DIFFUSEMAP
+ vec4 diffuseColor = texture2D(m_DiffuseMap, newTexCoord);
+ #else
+ vec4 diffuseColor = vec4(1.0);
+ #endif
+
+ #ifdef SPECULARMAP
+ vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
+ #else
+ vec4 specularColor = vec4(1.0);
+ #endif
+
+ diffuseColor.rgb *= DiffuseSum.rgb;
+ specularColor.rgb *= SpecularSum.rgb;
+
+ gl_FragData[0] = vec4(diffuseColor.rgb, 1.0);
+ gl_FragData[1] = vec4(encodeNormal(normal), 0.0, 0.0);
+ /*encodeNormal(vNormal));*/
+ gl_FragData[2] = vec4(specularColor.rgb, m_Shininess / 128.0);
+}
diff --git a/engine/src/core-data/Common/MatDefs/Light/GBuf.vert b/engine/src/core-data/Common/MatDefs/Light/GBuf.vert
new file mode 100644
index 0000000..f4ad199
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/GBuf.vert
@@ -0,0 +1,71 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform mat4 g_WorldMatrix;
+
+uniform vec4 m_Ambient;
+uniform vec4 m_Diffuse;
+uniform vec4 m_Specular;
+uniform float m_Shininess;
+
+varying vec2 texCoord;
+
+varying vec4 AmbientSum;
+varying vec4 DiffuseSum;
+varying vec4 SpecularSum;
+
+attribute vec3 inPosition;
+attribute vec2 inTexCoord;
+attribute vec3 inNormal;
+
+#ifdef NORMALMAP
+attribute vec3 inTangent;
+varying mat3 tbnMat;
+#endif
+
+#ifdef VERTEX_COLOR
+ attribute vec4 inColor;
+#endif
+
+varying vec3 vNormal;
+varying float vDepth;
+
+void main(){
+ vec4 pos = vec4(inPosition, 1.0);
+ gl_Position = g_WorldViewProjectionMatrix * pos;
+ texCoord = inTexCoord;
+
+ #if defined(NORMALMAP)
+ vec4 wvNormal, wvTangent, wvBinormal;
+
+ wvNormal = vec4(inNormal, 0.0);
+ wvTangent = vec4(inTangent, 0.0);
+
+ wvNormal.xyz = normalize( (g_WorldMatrix * wvNormal).xyz );
+ wvTangent.xyz = normalize( (g_WorldMatrix * wvTangent).xyz );
+ wvBinormal.xyz = cross(wvNormal.xyz, wvTangent.xyz);
+ tbnMat = mat3(wvTangent.xyz, wvBinormal.xyz, wvNormal.xyz);
+
+ vNormal = wvNormal.xyz;
+ #else
+ vec4 wvNormal;
+ #ifdef V_TANGENT
+ wvNormal = vec4(inTangent, 0.0);
+ #else
+ wvNormal = vec4(inNormal, 0.0);
+ #endif
+ vNormal = normalize( (g_WorldMatrix * wvNormal).xyz );
+ #endif
+
+ #ifdef MATERIAL_COLORS
+ AmbientSum = m_Ambient;
+ DiffuseSum = m_Diffuse;
+ SpecularSum = m_Specular;
+ #else
+ AmbientSum = vec4(0.0);
+ DiffuseSum = vec4(1.0);
+ SpecularSum = vec4(1.0);
+ #endif
+
+ #ifdef VERTEX_COLOR
+ DiffuseSum *= inColor;
+ #endif
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Light/Glow.frag b/engine/src/core-data/Common/MatDefs/Light/Glow.frag
new file mode 100644
index 0000000..a18a228
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/Glow.frag
@@ -0,0 +1,32 @@
+
+#if defined(NEED_TEXCOORD1)
+ varying vec2 texCoord1;
+#else
+ varying vec2 texCoord;
+#endif
+
+
+#ifdef HAS_GLOWMAP
+ uniform sampler2D m_GlowMap;
+#endif
+
+#ifdef HAS_GLOWCOLOR
+ uniform vec4 m_GlowColor;
+#endif
+
+
+void main(){
+ #ifdef HAS_GLOWMAP
+ #if defined(NEED_TEXCOORD1)
+ gl_FragColor = texture2D(m_GlowMap, texCoord1);
+ #else
+ gl_FragColor = texture2D(m_GlowMap, texCoord);
+ #endif
+ #else
+ #ifdef HAS_GLOWCOLOR
+ gl_FragColor = m_GlowColor;
+ #else
+ gl_FragColor = vec4(0.0);
+ #endif
+ #endif
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag
new file mode 100644
index 0000000..76f0e15
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag
@@ -0,0 +1,278 @@
+#import "Common/ShaderLib/Parallax.glsllib"
+#import "Common/ShaderLib/Optics.glsllib"
+#define ATTENUATION
+//#define HQ_ATTENUATION
+
+varying vec2 texCoord;
+#ifdef SEPARATE_TEXCOORD
+ varying vec2 texCoord2;
+#endif
+
+varying vec3 AmbientSum;
+varying vec4 DiffuseSum;
+varying vec3 SpecularSum;
+
+#ifndef VERTEX_LIGHTING
+ uniform vec4 g_LightDirection;
+ //varying vec3 vPosition;
+ varying vec3 vViewDir;
+ varying vec4 vLightDir;
+ varying vec3 lightVec;
+#else
+ varying vec2 vertexLightValues;
+#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;
+#else
+ varying vec3 vNormal;
+#endif
+
+#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 HQ_ATTENUATION
+uniform vec4 g_LightPosition;
+#endif
+
+#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;
+ #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
+
+ specularFactor *= diffuseFactor;
+
+ return vec2(diffuseFactor, specularFactor) * vec2(att);
+}
+#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
+ 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
+
+ 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
+ // ***********************
+ #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
+ vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
+ vec3 normal = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
+ #ifdef LATC
+ normal.z = sqrt(1.0 - (normal.x * normal.x) - (normal.y * normal.y));
+ #endif
+ //normal.y = -normal.y;
+ #elif !defined(VERTEX_LIGHTING)
+ vec3 normal = vNormal;
+ #if !defined(LOW_QUALITY) && !defined(V_TANGENT)
+ normal = normalize(normal);
+ #endif
+ #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
+ vec2 light = vertexLightValues.xy;
+ #ifdef COLORRAMP
+ light.x = texture2D(m_ColorRamp, vec2(light.x, 0.0)).r;
+ light.y = texture2D(m_ColorRamp, vec2(light.y, 0.0)).r;
+ #endif
+
+ gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
+ DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
+ SpecularSum * specularColor.rgb * vec3(light.y);
+ #else
+ vec4 lightDir = vLightDir;
+ lightDir.xyz = normalize(lightDir.xyz);
+ vec3 viewDir = normalize(vViewDir);
+
+ vec2 light = computeLighting(normal, viewDir, lightDir.xyz) * spotFallOff;
+ #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
+ vec4 refColor = Optics_GetEnvColor(m_EnvMap, refVec.xyz);
+
+ // 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 = AmbientSum * diffuseColor.rgb +
+ DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
+ SpecularSum2.rgb * specularColor.rgb * vec3(light.y);
+ #endif
+ gl_FragColor.a = alpha;
+}
diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md
new file mode 100644
index 0000000..95042b7
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md
@@ -0,0 +1,238 @@
+MaterialDef Phong Lighting {
+
+ MaterialParameters {
+
+ // Compute vertex lighting in the shader
+ // 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
+
+ // Apha threshold for fragment discarding
+ Float AlphaDiscardThreshold
+
+ // 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
+
+ // Ambient color
+ Color Ambient (MaterialAmbient)
+
+ // Diffuse color
+ Color Diffuse (MaterialDiffuse)
+
+ // Specular color
+ Color Specular (MaterialSpecular)
+
+ // Specular power/shininess
+ Float Shininess (MaterialShininess) : 1
+
+ // Diffuse map
+ Texture2D DiffuseMap
+
+ // Normal map
+ Texture2D NormalMap
+
+ // Specular/gloss map
+ Texture2D SpecularMap
+
+ // Parallax/height map
+ Texture2D ParallaxMap
+
+ //Set to true is parallax map is stored in the alpha channel of the normal map
+ Boolean PackedNormalParallax
+
+ //Sets the relief height for parallax mapping
+ Float ParallaxHeight : 0.05
+
+ //Set to true to activate Steep Parallax mapping
+ Boolean SteepParallax
+
+ // Texture that specifies alpha values
+ Texture2D AlphaMap
+
+ // Color ramp, will map diffuse and specular values through it.
+ Texture2D ColorRamp
+
+ // Texture of the glowing parts of the material
+ Texture2D GlowMap
+
+ // Set to Use Lightmap
+ Texture2D LightMap
+
+ // Set to use TexCoord2 for the lightmap sampling
+ Boolean SeparateTexCoord
+
+ // The glow color of the object
+ Color GlowColor
+
+ // Parameters for fresnel
+ // X = bias
+ // Y = scale
+ // Z = power
+ Vector3 FresnelParams
+
+ // Env Map for reflection
+ TextureCubeMap EnvMap
+
+ // the env map is a spheremap and not a cube map
+ Boolean EnvMapAsSphereMap
+ }
+
+ Technique {
+
+ LightMode MultiPass
+
+ VertexShader GLSL100: Common/MatDefs/Light/Lighting.vert
+ FragmentShader GLSL100: Common/MatDefs/Light/Lighting.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ NormalMatrix
+ WorldViewMatrix
+ ViewMatrix
+ CameraPosition
+ WorldMatrix
+ }
+
+ Defines {
+ LATC : LATC
+ VERTEX_COLOR : UseVertexColor
+ VERTEX_LIGHTING : VertexLighting
+ ATTENUATION : Attenuation
+ MATERIAL_COLORS : UseMaterialColors
+ V_TANGENT : VTangent
+ MINNAERT : Minnaert
+ WARDISO : WardIso
+ LOW_QUALITY : LowQuality
+ HQ_ATTENUATION : HighQuality
+
+ DIFFUSEMAP : DiffuseMap
+ NORMALMAP : NormalMap
+ SPECULARMAP : SpecularMap
+ PARALLAXMAP : ParallaxMap
+ NORMALMAP_PARALLAX : PackedNormalParallax
+ STEEP_PARALLAX : SteepParallax
+ ALPHAMAP : AlphaMap
+ COLORRAMP : ColorRamp
+ LIGHTMAP : LightMap
+ SEPARATE_TEXCOORD : SeparateTexCoord
+
+ USE_REFLECTION : EnvMap
+ SPHERE_MAP : SphereMap
+ }
+ }
+
+ Technique PreShadow {
+
+ VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
+ FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ }
+
+ Defines {
+ DIFFUSEMAP_ALPHA : DiffuseMap
+ }
+
+ RenderState {
+ FaceCull Off
+ DepthTest On
+ DepthWrite On
+ PolyOffset 5 0
+ ColorWrite Off
+ }
+
+ }
+
+ Technique PreNormalPass {
+
+ VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert
+ FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ NormalMatrix
+ }
+
+ Defines {
+ DIFFUSEMAP_ALPHA : DiffuseMap
+ }
+
+ RenderState {
+
+ }
+
+ }
+
+ Technique GBuf {
+
+ VertexShader GLSL100: Common/MatDefs/Light/GBuf.vert
+ FragmentShader GLSL100: Common/MatDefs/Light/GBuf.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ NormalMatrix
+ WorldViewMatrix
+ WorldMatrix
+ }
+
+ Defines {
+ VERTEX_COLOR : UseVertexColor
+ MATERIAL_COLORS : UseMaterialColors
+ V_TANGENT : VTangent
+ MINNAERT : Minnaert
+ WARDISO : WardIso
+
+ DIFFUSEMAP : DiffuseMap
+ NORMALMAP : NormalMap
+ SPECULARMAP : SpecularMap
+ PARALLAXMAP : ParallaxMap
+ }
+ }
+
+ Technique FixedFunc {
+ LightMode FixedPipeline
+ }
+
+ Technique Glow {
+
+ VertexShader GLSL100: Common/MatDefs/Misc/SimpleTextured.vert
+ FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ HAS_GLOWMAP : GlowMap
+ HAS_GLOWCOLOR : GlowColor
+ }
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.vert b/engine/src/core-data/Common/MatDefs/Light/Lighting.vert
new file mode 100644
index 0000000..042cba9
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.vert
@@ -0,0 +1,207 @@
+#define ATTENUATION
+//#define HQ_ATTENUATION
+
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform mat4 g_WorldViewMatrix;
+uniform mat3 g_NormalMatrix;
+uniform mat4 g_ViewMatrix;
+
+uniform vec4 m_Ambient;
+uniform vec4 m_Diffuse;
+uniform vec4 m_Specular;
+uniform float m_Shininess;
+
+uniform vec4 g_LightColor;
+uniform vec4 g_LightPosition;
+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;
+
+varying vec3 lightVec;
+//varying vec4 spotVec;
+
+#ifdef VERTEX_COLOR
+ attribute vec4 inColor;
+#endif
+
+#ifndef VERTEX_LIGHTING
+ attribute vec4 inTangent;
+
+ #ifndef NORMALMAP
+ varying vec3 vNormal;
+ #endif
+ //varying vec3 vPosition;
+ varying vec3 vViewDir;
+ varying vec4 vLightDir;
+#else
+ varying vec2 vertexLightValues;
+ uniform vec4 g_LightDirection;
+#endif
+
+#ifdef USE_REFLECTION
+ uniform vec3 g_CameraPosition;
+ uniform mat4 g_WorldMatrix;
+
+ uniform vec3 m_FresnelParams;
+ varying vec4 refVec;
+
+
+ /**
+ * Input:
+ * attribute inPosition
+ * attribute inNormal
+ * uniform g_WorldMatrix
+ * uniform g_CameraPosition
+ *
+ * Output:
+ * varying refVec
+ */
+ void computeRef(){
+ vec3 worldPos = (g_WorldMatrix * vec4(inPosition,1.0)).xyz;
+
+ vec3 I = normalize( g_CameraPosition - worldPos ).xyz;
+ vec3 N = normalize( (g_WorldMatrix * 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
+
+// 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 pos = vec4(inPosition, 1.0);
+ gl_Position = g_WorldViewProjectionMatrix * pos;
+ texCoord = inTexCoord;
+ #ifdef SEPARATE_TEXCOORD
+ texCoord2 = inTexCoord2;
+ #endif
+
+ vec3 wvPosition = (g_WorldViewMatrix * pos).xyz;
+ vec3 wvNormal = normalize(g_NormalMatrix * inNormal);
+ 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;
+
+ #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
+ vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz);
+ 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);
+ 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(g_NormalMatrix * inTangent.xyz);
+ vNormal = -cross(cross(vLightDir.xyz, vNormal), vNormal);
+ #endif
+ #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;
+ 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;
+ SpecularSum = vec3(0.0);
+ #endif
+
+ #ifdef VERTEX_COLOR
+ AmbientSum *= inColor.rgb;
+ DiffuseSum *= inColor;
+ #endif
+
+ #ifdef VERTEX_LIGHTING
+ vertexLightValues = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
+ #endif
+
+ #ifdef USE_REFLECTION
+ computeRef();
+ #endif
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.frag b/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.frag
new file mode 100644
index 0000000..272f100
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.frag
@@ -0,0 +1,9 @@
+varying vec2 texCoord;
+
+uniform sampler2D m_ColorMap;
+uniform vec4 m_Color;
+
+void main(){
+ vec4 texColor = texture2D(m_ColorMap, texCoord);
+ gl_FragColor = vec4(mix(m_Color.rgb, texColor.rgb, texColor.a), 1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.j3md b/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.j3md
new file mode 100644
index 0000000..dde8ea8
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.j3md
@@ -0,0 +1,20 @@
+MaterialDef Colored Textured {
+
+ MaterialParameters {
+ Texture2D ColorMap
+ Color Color
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Misc/ColoredTextured.vert
+ FragmentShader GLSL100: Common/MatDefs/Misc/ColoredTextured.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.vert b/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.vert
new file mode 100644
index 0000000..572d841
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/ColoredTextured.vert
@@ -0,0 +1,11 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+
+attribute vec3 inPosition;
+attribute vec2 inTexCoord;
+
+varying vec2 texCoord;
+
+void main(){
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
+ texCoord = inTexCoord;
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Particle.frag b/engine/src/core-data/Common/MatDefs/Misc/Particle.frag
new file mode 100644
index 0000000..08cd2a3
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Particle.frag
@@ -0,0 +1,22 @@
+#ifdef USE_TEXTURE
+uniform sampler2D m_Texture;
+varying vec4 texCoord;
+#endif
+
+varying vec4 color;
+
+void main(){
+ if (color.a <= 0.01)
+ discard;
+
+ #ifdef USE_TEXTURE
+ #ifdef POINT_SPRITE
+ vec2 uv = mix(texCoord.xy, texCoord.zw, gl_PointCoord.xy);
+ #else
+ vec2 uv = texCoord.xy;
+ #endif
+ gl_FragColor = texture2D(m_Texture, uv) * color;
+ #else
+ gl_FragColor = color;
+ #endif
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md b/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md
new file mode 100644
index 0000000..e28d41a
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md
@@ -0,0 +1,89 @@
+MaterialDef Point Sprite {
+
+ MaterialParameters {
+ Texture2D Texture
+ Float Quadratic
+ Boolean PointSprite
+
+ // Texture of the glowing parts of the material
+ Texture2D GlowMap
+ // The glow color of the object
+ Color GlowColor
+ }
+
+ Technique {
+
+ VertexShader GLSL100 : Common/MatDefs/Misc/Particle.vert
+ FragmentShader GLSL120 : Common/MatDefs/Misc/Particle.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ WorldMatrix
+ CameraPosition
+ }
+
+ RenderState {
+ Blend AlphaAdditive
+ DepthWrite Off
+ PointSprite On
+ // AlphaTestFalloff 0.01
+ }
+
+ Defines {
+ USE_TEXTURE : Texture
+ POINT_SPRITE : PointSprite
+ }
+ }
+
+ Technique {
+
+ VertexShader GLSL100 : Common/MatDefs/Misc/Particle.vert
+ FragmentShader GLSL100 : Common/MatDefs/Misc/Particle.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ WorldMatrix
+ CameraPosition
+ }
+
+ RenderState {
+ Blend AlphaAdditive
+ DepthWrite Off
+ }
+
+ Defines {
+ USE_TEXTURE : Texture
+ }
+ }
+
+ Technique FixedFunc {
+ RenderState {
+ Blend AlphaAdditive
+ // DepthWrite Off
+ // AlphaTestFalloff 0.01
+ }
+ }
+
+ Technique Glow {
+
+ VertexShader GLSL100: Common/MatDefs/Misc/SimpleTextured.vert
+ FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ HAS_GLOWMAP : GlowMap
+ HAS_GLOWCOLOR : GlowColor
+ }
+
+ RenderState {
+ PointSprite On
+ Blend AlphaAdditive
+ DepthWrite Off
+ }
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Particle.vert b/engine/src/core-data/Common/MatDefs/Misc/Particle.vert
new file mode 100644
index 0000000..9c27336
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Particle.vert
@@ -0,0 +1,42 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+
+attribute vec3 inPosition;
+attribute vec4 inColor;
+attribute vec4 inTexCoord;
+
+varying vec4 color;
+
+#ifdef USE_TEXTURE
+varying vec4 texCoord;
+#endif
+
+#ifdef POINT_SPRITE
+uniform mat4 g_WorldViewMatrix;
+uniform mat4 g_WorldMatrix;
+uniform vec3 g_CameraPosition;
+uniform float m_Quadratic;
+const float SIZE_MULTIPLIER = 4.0;
+attribute float inSize;
+#endif
+
+void main(){
+ vec4 pos = vec4(inPosition, 1.0);
+
+ gl_Position = g_WorldViewProjectionMatrix * pos;
+ color = inColor;
+
+ #ifdef USE_TEXTURE
+ texCoord = inTexCoord;
+ #endif
+
+ #ifdef POINT_SPRITE
+ vec4 worldPos = g_WorldMatrix * pos;
+ float d = distance(g_CameraPosition.xyz, worldPos.xyz);
+ gl_PointSize = max(1.0, (inSize * SIZE_MULTIPLIER * m_Quadratic) / d);
+
+ //vec4 worldViewPos = g_WorldViewMatrix * pos;
+ //gl_PointSize = (inSize * SIZE_MULTIPLIER * m_Quadratic)*100.0 / worldViewPos.z;
+
+ color.a *= min(gl_PointSize, 1.0);
+ #endif
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.frag b/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.frag
new file mode 100644
index 0000000..93e4882
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.frag
@@ -0,0 +1,5 @@
+varying vec3 normal;
+
+void main(){
+ gl_FragColor = vec4((normal * vec3(0.5)) + vec3(0.5), 1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.j3md b/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.j3md
new file mode 100644
index 0000000..db480b7
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.j3md
@@ -0,0 +1,10 @@
+MaterialDef Debug Normals {
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Misc/ShowNormals.vert
+ FragmentShader GLSL100: Common/MatDefs/Misc/ShowNormals.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.vert b/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.vert
new file mode 100644
index 0000000..3813043
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/ShowNormals.vert
@@ -0,0 +1,11 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+
+attribute vec3 inPosition;
+attribute vec3 inNormal;
+
+varying vec3 normal;
+
+void main(){
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition,1.0);
+ normal = inNormal;
+}
diff --git a/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.frag b/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.frag
new file mode 100644
index 0000000..395f3d1
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.frag
@@ -0,0 +1,27 @@
+#import "Common/ShaderLib/Texture.glsllib"
+
+varying vec2 texCoord;
+
+uniform sampler2D m_ColorMap;
+
+void main(){
+ //Texture_GetColor(m_ColorMap, texCoord)
+ //vec4 color = texture2D(m_ColorMap, texCoord);
+ //color.rgb *= color.a;
+ //gl_FragColor = vec4(color.a);
+
+ #ifdef NORMAL_LATC
+ vec3 newNorm = vec3(texture2D(m_ColorMap, texCoord).ag, 0.0);
+ newNorm = Common_UnpackNormal(newNorm);
+ newNorm.b = sqrt(1.0 - (newNorm.x * newNorm.x) - (newNorm.y * newNorm.y));
+ newNorm = Common_PackNormal(newNorm);
+ gl_FragColor = vec4(newNorm, 1.0);
+ #elif defined(SHOW_ALPHA)
+ gl_FragColor = vec4(texture2D(m_ColorMap, texCoord).a);
+ #else
+ gl_FragColor = Texture_GetColor(m_ColorMap, texCoord);
+ #endif
+ #ifdef NORMALIZE
+ gl_FragColor = vec4(normalize(gl_FragColor.xyz), gl_FragColor.a);
+ #endif
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.j3md b/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.j3md
new file mode 100644
index 0000000..53469e2
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.j3md
@@ -0,0 +1,32 @@
+Exception SimpleTextured.j3md has been marked as obsolete. Please use Unshaded.j3md instead.
+
+MaterialDef Plain Texture {
+
+ MaterialParameters {
+ Texture2D ColorMap
+ Boolean YCoCg
+ Boolean LATC
+ Boolean Normalize
+ Boolean ShowAlpha
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Misc/SimpleTextured.vert
+ FragmentShader GLSL100: Common/MatDefs/Misc/SimpleTextured.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ DXT_YCOCG : YCoCg
+ NORMAL_LATC : LATC
+ NORMALIZE : Normalize
+ SHOW_ALPHA : ShowAlpha
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.vert b/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.vert
new file mode 100644
index 0000000..572d841
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/SimpleTextured.vert
@@ -0,0 +1,11 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+
+attribute vec3 inPosition;
+attribute vec2 inTexCoord;
+
+varying vec2 texCoord;
+
+void main(){
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
+ texCoord = inTexCoord;
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Sky.frag b/engine/src/core-data/Common/MatDefs/Misc/Sky.frag
new file mode 100644
index 0000000..3e36e0a
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Sky.frag
@@ -0,0 +1,11 @@
+#import "Common/ShaderLib/Optics.glsllib"
+
+uniform ENVMAP m_Texture;
+
+varying vec3 direction;
+
+void main() {
+ vec3 dir = normalize(direction);
+ gl_FragColor = Optics_GetEnvColor(m_Texture, direction);
+}
+
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Sky.j3md b/engine/src/core-data/Common/MatDefs/Misc/Sky.j3md
new file mode 100644
index 0000000..919309b
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Sky.j3md
@@ -0,0 +1,27 @@
+MaterialDef Sky Plane {
+ MaterialParameters {
+ TextureCubeMap Texture
+ Boolean SphereMap
+ Vector3 NormalScale
+ }
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Misc/Sky.vert
+ FragmentShader GLSL100: Common/MatDefs/Misc/Sky.frag
+
+ RenderState {
+ FaceCull Off
+ }
+
+ WorldParameters {
+ ViewMatrix
+ ProjectionMatrix
+ WorldMatrix
+ }
+
+ Defines {
+ SPHERE_MAP : SphereMap
+ }
+ }
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Sky.vert b/engine/src/core-data/Common/MatDefs/Misc/Sky.vert
new file mode 100644
index 0000000..0426f87
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Sky.vert
@@ -0,0 +1,25 @@
+uniform mat4 g_ViewMatrix;
+uniform mat4 g_ProjectionMatrix;
+uniform mat4 g_WorldMatrix;
+
+uniform vec3 m_NormalScale;
+
+attribute vec3 inPosition;
+attribute vec3 inNormal;
+
+varying vec3 direction;
+
+void main(){
+ // set w coordinate to 0
+ vec4 pos = vec4(inPosition, 0.0);
+
+ // compute rotation only for view matrix
+ pos = g_ViewMatrix * pos;
+
+ // now find projection
+ pos.w = 1.0;
+ gl_Position = g_ProjectionMatrix * pos;
+
+ vec4 normal = vec4(inNormal * m_NormalScale, 0.0);
+ direction = normalize( (g_WorldMatrix * normal).xyz );
+}
diff --git a/engine/src/core-data/Common/MatDefs/Misc/SolidColor.j3md b/engine/src/core-data/Common/MatDefs/Misc/SolidColor.j3md
new file mode 100644
index 0000000..15cdff2
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/SolidColor.j3md
@@ -0,0 +1,44 @@
+Exception SolidColor.j3md has been marked as obsolete. Please use Unshaded.j3md instead.
+
+MaterialDef Solid Color {
+
+ MaterialParameters {
+ Vector4 Color
+
+ // Texture of the glowing parts of the material
+ Texture2D GlowMap
+ // The glow color of the object
+ Color GlowColor
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Misc/Unshaded.vert
+ FragmentShader GLSL100: Common/MatDefs/Misc/Unshaded.frag
+
+ Defines {
+ HAS_COLOR : Color
+ }
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+ Technique Glow {
+
+ VertexShader GLSL100: Common/MatDefs/Misc/Unshaded.vert
+ FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ HAS_GLOWMAP : GlowMap
+ HAS_GLOWCOLOR : GlowColor
+ }
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Unshaded.frag b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.frag
new file mode 100644
index 0000000..ab28778
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.frag
@@ -0,0 +1,50 @@
+uniform vec4 m_Color;
+
+#if defined(HAS_GLOWMAP) || defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
+ #define NEED_TEXCOORD1
+#endif
+
+#ifdef HAS_COLORMAP
+ uniform sampler2D m_ColorMap;
+#endif
+
+#ifdef NEED_TEXCOORD1
+ varying vec2 texCoord1;
+#endif
+
+#ifdef HAS_LIGHTMAP
+ uniform sampler2D m_LightMap;
+ #ifdef SEPARATE_TEXCOORD
+ varying vec2 texCoord2;
+ #endif
+#endif
+
+#ifdef HAS_VERTEXCOLOR
+ varying vec4 vertColor;
+#endif
+
+void main(){
+ vec4 color = vec4(1.0);
+
+ #ifdef HAS_COLORMAP
+ color *= texture2D(m_ColorMap, texCoord1);
+ #endif
+
+ #ifdef HAS_VERTEXCOLOR
+ color *= vertColor;
+ #endif
+
+ #ifdef HAS_COLOR
+ color *= m_Color;
+ #endif
+
+ #ifdef HAS_LIGHTMAP
+ #ifdef SEPARATE_TEXCOORD
+ color.rgb *= texture2D(m_LightMap, texCoord2).rgb;
+ #else
+ color.rgb *= texture2D(m_LightMap, texCoord1).rgb;
+ #endif
+ #endif
+
+ gl_FragColor = color;
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md
new file mode 100644
index 0000000..5a33d44
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md
@@ -0,0 +1,70 @@
+MaterialDef Unshaded {
+
+ MaterialParameters {
+ Texture2D ColorMap
+ Texture2D LightMap
+ Color Color ( Color )
+ Boolean VertexColor
+ Boolean SeparateTexCoord
+
+ // Texture of the glowing parts of the material
+ Texture2D GlowMap
+ // The glow color of the object
+ Color GlowColor
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Misc/Unshaded.vert
+ FragmentShader GLSL100: Common/MatDefs/Misc/Unshaded.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ SEPARATE_TEXCOORD : SeparateTexCoord
+ HAS_COLORMAP : ColorMap
+ HAS_LIGHTMAP : LightMap
+ HAS_VERTEXCOLOR : VertexColor
+ HAS_COLOR : Color
+ }
+ }
+
+ Technique PreNormalPass {
+
+ VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert
+ FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ NormalMatrix
+ }
+
+ RenderState {
+
+ }
+
+ }
+
+
+ Technique Glow {
+
+ VertexShader GLSL100: Common/MatDefs/Misc/Unshaded.vert
+ FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ HAS_GLOWMAP : GlowMap
+ HAS_GLOWCOLOR : GlowColor
+ HAS_COLORMAP // Must be passed so that Unshaded.vert exports texCoord.
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Unshaded.vert b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.vert
new file mode 100644
index 0000000..7bf9f7e
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.vert
@@ -0,0 +1,37 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+attribute vec3 inPosition;
+
+#if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
+ #define NEED_TEXCOORD1
+#endif
+
+#ifdef NEED_TEXCOORD1
+ attribute vec2 inTexCoord;
+ varying vec2 texCoord1;
+#endif
+
+#ifdef SEPARATE_TEXCOORD
+ attribute vec2 inTexCoord2;
+ varying vec2 texCoord2;
+#endif
+
+#ifdef HAS_VERTEXCOLOR
+ attribute vec4 inColor;
+ varying vec4 vertColor;
+#endif
+
+void main(){
+ #ifdef NEED_TEXCOORD1
+ texCoord1 = inTexCoord;
+ #endif
+
+ #ifdef SEPARATE_TEXCOORD
+ texCoord2 = inTexCoord2;
+ #endif
+
+ #ifdef HAS_VERTEXCOLOR
+ vertColor = inColor;
+ #endif
+
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/VertexColor.j3md b/engine/src/core-data/Common/MatDefs/Misc/VertexColor.j3md
new file mode 100644
index 0000000..d5b3eba
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/VertexColor.j3md
@@ -0,0 +1,18 @@
+Exception VertexColor.j3md has been marked as obsolete. Please use Unshaded.j3md instead.
+
+MaterialDef Vertex Color {
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Misc/Unshaded.vert
+ FragmentShader GLSL100: Common/MatDefs/Misc/Unshaded.frag
+
+ Defines {
+ HAS_VERTEXCOLOR
+ }
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/WireColor.j3md b/engine/src/core-data/Common/MatDefs/Misc/WireColor.j3md
new file mode 100644
index 0000000..51a4733
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/WireColor.j3md
@@ -0,0 +1,38 @@
+Exception WireColor.j3md has been marked as obsolete. Please use Unshaded.j3md instead.
+
+MaterialDef Wire Color {
+
+ MaterialParameters {
+ Vector4 Color : Color
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Misc/Unshaded.vert
+ FragmentShader GLSL100: Common/MatDefs/Misc/Unshaded.frag
+
+ RenderState {
+ FaceCull Off
+ Blend Alpha
+ AlphaTestFalloff 0.01
+ Wireframe On
+ }
+
+ Defines {
+ HAS_COLOR : Color
+ }
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ RenderState {
+ FaceCull Off
+ Blend Alpha
+ AlphaTestFalloff 0.01
+ Wireframe On
+ }
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.frag b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.frag
new file mode 100644
index 0000000..8c3d133
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.frag
@@ -0,0 +1,12 @@
+#import "Common/ShaderLib/Shadow.glsllib"
+
+uniform SHADOWMAP m_ShadowMap;
+varying vec4 projCoord;
+
+void main() {
+ vec4 coord = projCoord;
+ coord.xyz /= coord.w;
+ float shad = Shadow_GetShadow(m_ShadowMap, coord) * 0.7 + 0.3;
+ gl_FragColor = vec4(shad,shad,shad,1.0);
+}
+
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md
new file mode 100644
index 0000000..0fc8bfc
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md
@@ -0,0 +1,26 @@
+MaterialDef Post Shadow {
+
+ MaterialParameters {
+ Texture2D ShadowMap
+ Matrix4 LightViewProjectionMatrix
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Shadow/PostShadow.vert
+ FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadow.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldMatrix
+ }
+
+ Defines {
+ NO_SHADOW2DPROJ
+ }
+
+ RenderState {
+ Blend Modulate
+ }
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert
new file mode 100644
index 0000000..3f09753
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert
@@ -0,0 +1,31 @@
+uniform mat4 m_LightViewProjectionMatrix;
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform mat4 g_WorldMatrix;
+
+varying vec4 projCoord;
+
+attribute vec3 inPosition;
+
+const mat4 biasMat = mat4(0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0);
+
+void main(){
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
+
+ // get the vertex in world space
+ vec4 worldPos = g_WorldMatrix * vec4(inPosition, 1.0);
+
+ // convert vertex to light viewProj space
+ //projCoord = biasMat * (m_LightViewProjectionMatrix * worldPos);
+ vec4 coord = m_LightViewProjectionMatrix * worldPos;
+ projCoord = biasMat * coord;
+ //projCoord.z /= gl_DepthRange.far;
+ //projCoord = (m_LightViewProjectionMatrix * worldPos);
+ //projCoord /= projCoord.w;
+ //projCoord.xy = projCoord.xy * vec2(0.5, -0.5) + vec2(0.5);
+
+ // bias from [-1, 1] to [0, 1] for sampling shadow map
+ //projCoord = (projCoord.xyzw * vec4(0.5)) + vec4(0.5);
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag
new file mode 100644
index 0000000..ab5993b
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.frag
@@ -0,0 +1,119 @@
+#ifdef HARDWARE_SHADOWS
+ #define SHADOWMAP sampler2DShadow
+ #define SHADOWCOMPARE(tex,coord) shadow2DProj(tex, coord).r
+#else
+ #define SHADOWMAP sampler2D
+ #define SHADOWCOMPARE(tex,coord) step(coord.z, texture2DProj(tex, coord).r)
+#endif
+
+#if FILTER_MODE == 0
+ #define GETSHADOW Shadow_DoShadowCompare
+ #define KERNEL 1.0
+#elif FILTER_MODE == 1
+ #ifdef HARDWARE_SHADOWS
+ #define GETSHADOW Shadow_DoShadowCompare
+ #else
+ #define GETSHADOW Shadow_DoBilinear_2x2
+ #endif
+ #define KERNEL 1.0
+#elif FILTER_MODE == 2
+ #define GETSHADOW Shadow_DoDither_2x2
+ #define KERNEL 1.0
+#elif FILTER_MODE == 3
+ #define GETSHADOW Shadow_DoPCF
+ #define KERNEL 4.0
+#elif FILTER_MODE == 4
+ #define GETSHADOW Shadow_DoPCF
+ #define KERNEL 8.0
+#endif
+
+uniform SHADOWMAP m_ShadowMap0;
+uniform SHADOWMAP m_ShadowMap1;
+uniform SHADOWMAP m_ShadowMap2;
+uniform SHADOWMAP m_ShadowMap3;
+
+uniform vec4 m_Splits;
+
+uniform float m_ShadowIntensity;
+
+varying vec4 projCoord0;
+varying vec4 projCoord1;
+varying vec4 projCoord2;
+varying vec4 projCoord3;
+
+varying float shadowPosition;
+
+const float texSize = 1024.0;
+const float pixSize = 1.0 / texSize;
+const vec2 pixSize2 = vec2(pixSize);
+
+float Shadow_DoShadowCompareOffset(in SHADOWMAP tex, in vec4 projCoord, in vec2 offset){
+ vec4 coord = vec4(projCoord.xy + offset.xy * pixSize2, projCoord.zw);
+ return SHADOWCOMPARE(tex, coord);
+}
+
+float Shadow_DoShadowCompare(in SHADOWMAP tex, vec4 projCoord){
+ return SHADOWCOMPARE(tex, projCoord);
+}
+
+float Shadow_BorderCheck(in vec2 coord){
+ // Fastest, "hack" method (uses 4-5 instructions)
+ vec4 t = vec4(coord.xy, 0.0, 1.0);
+ t = step(t.wwxy, t.xyzz);
+ return dot(t,t);
+}
+
+float Shadow_DoDither_2x2(in SHADOWMAP tex, in vec4 projCoord){
+ float shadow = 0.0;
+ vec2 o = mod(floor(gl_FragCoord.xy), 2.0);
+ shadow += Shadow_DoShadowCompareOffset(tex,projCoord,vec2(-1.5, 1.5) + o);
+ shadow += Shadow_DoShadowCompareOffset(tex,projCoord,vec2( 0.5, 1.5) + o);
+ shadow += Shadow_DoShadowCompareOffset(tex,projCoord,vec2(-1.5, -0.5) + o);
+ shadow += Shadow_DoShadowCompareOffset(tex,projCoord,vec2( 0.5, -0.5) + o);
+ shadow *= 0.25 ;
+ return shadow;
+}
+
+float Shadow_DoBilinear_2x2(in SHADOWMAP tex, in vec4 projCoord){
+ vec4 gather = vec4(0.0);
+ gather.x = Shadow_DoShadowCompareOffset(tex, projCoord, vec2(0.0, 0.0));
+ gather.y = Shadow_DoShadowCompareOffset(tex, projCoord, vec2(1.0, 0.0));
+ gather.z = Shadow_DoShadowCompareOffset(tex, projCoord, vec2(0.0, 1.0));
+ gather.w = Shadow_DoShadowCompareOffset(tex, projCoord, vec2(1.0, 1.0));
+
+ vec2 f = fract( projCoord.xy * texSize );
+ vec2 mx = mix( gather.xz, gather.yw, f.x );
+ return mix( mx.x, mx.y, f.y );
+}
+
+float Shadow_DoPCF(in SHADOWMAP tex, in vec4 projCoord){
+ float shadow = 0.0;
+ float bound = KERNEL * 0.5 - 0.5;
+ bound *= PCFEDGE;
+ for (float y = -bound; y <= bound; y += PCFEDGE){
+ for (float x = -bound; x <= bound; x += PCFEDGE){
+ shadow += clamp(Shadow_DoShadowCompareOffset(tex,projCoord,vec2(x,y)) +
+ Shadow_BorderCheck(projCoord.xy),
+ 0.0, 1.0);
+ }
+ }
+
+ shadow = shadow / (KERNEL * KERNEL);
+ return shadow;
+}
+
+void main(){
+ vec4 shadowPerSplit = vec4(0.0);
+ shadowPerSplit.x = GETSHADOW(m_ShadowMap0, projCoord0);
+ shadowPerSplit.y = GETSHADOW(m_ShadowMap1, projCoord1);
+ shadowPerSplit.z = GETSHADOW(m_ShadowMap2, projCoord2);
+ shadowPerSplit.w = GETSHADOW(m_ShadowMap3, projCoord3);
+
+ vec4 less = step( shadowPosition, m_Splits );
+ vec4 more = vec4(1.0) - step( shadowPosition, vec4(0.0, m_Splits.xyz) );
+ float shadow = dot(shadowPerSplit, less * more );
+
+ shadow = shadow * m_ShadowIntensity + (1.0 - m_ShadowIntensity);
+ gl_FragColor = vec4(shadow, shadow, shadow, 1.0);
+}
+
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md
new file mode 100644
index 0000000..8b75748
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.j3md
@@ -0,0 +1,63 @@
+MaterialDef Post Shadow {
+
+ MaterialParameters {
+ Int FilterMode
+ Boolean HardwareShadows
+
+ Texture2D ShadowMap0
+ Texture2D ShadowMap1
+ Texture2D ShadowMap2
+ Texture2D ShadowMap3
+
+ Float ShadowIntensity
+ Vector4 Splits
+
+ Matrix4 LightViewProjectionMatrix0
+ Matrix4 LightViewProjectionMatrix1
+ Matrix4 LightViewProjectionMatrix2
+ Matrix4 LightViewProjectionMatrix3
+
+ Float PCFEdge
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Shadow/PostShadowPSSM.vert
+ FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadowPSSM15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldMatrix
+ }
+
+ Defines {
+ HARDWARE_SHADOWS : HardwareShadows
+ FILTER_MODE : FilterMode
+ PCFEDGE : PCFEdge
+ }
+
+ RenderState {
+ Blend Modulate
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Shadow/PostShadowPSSM.vert
+ FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadowPSSM.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldMatrix
+ }
+
+ Defines {
+ HARDWARE_SHADOWS : HardwareShadows
+ FILTER_MODE : FilterMode
+ PCFEDGE : PCFEdge
+ }
+
+ RenderState {
+ Blend Modulate
+ }
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert
new file mode 100644
index 0000000..b1c1690
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM.vert
@@ -0,0 +1,37 @@
+uniform mat4 m_LightViewProjectionMatrix0;
+uniform mat4 m_LightViewProjectionMatrix1;
+uniform mat4 m_LightViewProjectionMatrix2;
+uniform mat4 m_LightViewProjectionMatrix3;
+
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform mat4 g_WorldMatrix;
+
+varying vec4 projCoord0;
+varying vec4 projCoord1;
+varying vec4 projCoord2;
+varying vec4 projCoord3;
+
+varying float shadowPosition;
+
+attribute vec3 inPosition;
+
+const mat4 biasMat = mat4(0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0);
+
+
+void main(){
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
+
+ shadowPosition = gl_Position.z;
+ // get the vertex in world space
+ vec4 worldPos = g_WorldMatrix * vec4(inPosition, 1.0);
+
+
+ // populate the light view matrices array and convert vertex to light viewProj space
+ projCoord0 = biasMat * m_LightViewProjectionMatrix0 * worldPos;
+ projCoord1 = biasMat * m_LightViewProjectionMatrix1 * worldPos;
+ projCoord2 = biasMat * m_LightViewProjectionMatrix2 * worldPos;
+ projCoord3 = biasMat * m_LightViewProjectionMatrix3 * worldPos;
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag
new file mode 100644
index 0000000..0dc1ddf
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowPSSM15.frag
@@ -0,0 +1,139 @@
+// Because gpu_shader5 is actually where those
+// gather functions are declared to work on shadowmaps
+#extension GL_ARB_gpu_shader5 : enable
+
+#ifdef HARDWARE_SHADOWS
+ #define SHADOWMAP sampler2DShadow
+ #define SHADOWCOMPAREOFFSET(tex,coord,offset) textureProjOffset(tex, coord, offset)
+ #define SHADOWCOMPARE(tex,coord) textureProj(tex, coord)
+ #define SHADOWGATHER(tex,coord) textureGather(tex, coord.xy, coord.z)
+#else
+ #define SHADOWMAP sampler2D
+ #define SHADOWCOMPAREOFFSET(tex,coord,offset) step(coord.z, textureProjOffset(tex, coord, offset).r)
+ #define SHADOWCOMPARE(tex,coord) step(coord.z, textureProj(tex, coord).r)
+ #define SHADOWGATHER(tex,coord) step(coord.z, textureGather(tex, coord.xy))
+#endif
+
+
+#if FILTER_MODE == 0
+ #define GETSHADOW SHADOWCOMPARE
+ #define KERNEL 1
+#elif FILTER_MODE == 1
+ #ifdef HARDWARE_SHADOWS
+ #define GETSHADOW SHADOWCOMPARE
+ #else
+ #define GETSHADOW Shadow_DoBilinear_2x2
+ #endif
+ #define KERNEL 1
+#elif FILTER_MODE == 2
+ #define GETSHADOW Shadow_DoDither_2x2
+ #define KERNEL 1
+#elif FILTER_MODE == 3
+ #define GETSHADOW Shadow_DoPCF
+ #define KERNEL 4
+#elif FILTER_MODE == 4
+ #define GETSHADOW Shadow_DoPCF
+ #define KERNEL 8
+#endif
+
+out vec4 outFragColor;
+
+uniform SHADOWMAP m_ShadowMap0;
+uniform SHADOWMAP m_ShadowMap1;
+uniform SHADOWMAP m_ShadowMap2;
+uniform SHADOWMAP m_ShadowMap3;
+
+uniform vec4 m_Splits;
+uniform float m_ShadowIntensity;
+
+in vec4 projCoord0;
+in vec4 projCoord1;
+in vec4 projCoord2;
+in vec4 projCoord3;
+in float shadowPosition;
+
+float Shadow_BorderCheck(in vec2 coord){
+ // Fastest, "hack" method (uses 4-5 instructions)
+ vec4 t = vec4(coord.xy, 0.0, 1.0);
+ t = step(t.wwxy, t.xyzz);
+ return dot(t,t);
+}
+
+float Shadow_DoDither_2x2(in SHADOWMAP tex, in vec4 projCoord){
+ float border = Shadow_BorderCheck(projCoord.xy);
+ if (border > 0.0)
+ return 1.0;
+
+ ivec2 texSize = textureSize(tex, 0);
+ vec2 pixSize = 1.0 / vec2(texSize);
+
+ float shadow = 0.0;
+ ivec2 o = ivec2(mod(floor(gl_FragCoord.xy), 2.0));
+ shadow += SHADOWCOMPARE(tex, vec4(projCoord.xy+pixSize*(vec2(-1.5, 1.5)+o), projCoord.zw));
+ shadow += SHADOWCOMPARE(tex, vec4(projCoord.xy+pixSize*(vec2( 0.5, 1.5)+o), projCoord.zw));
+ shadow += SHADOWCOMPARE(tex, vec4(projCoord.xy+pixSize*(vec2(-1.5, -0.5)+o), projCoord.zw));
+ shadow += SHADOWCOMPARE(tex, vec4(projCoord.xy+pixSize*(vec2( 0.5, -0.5)+o), projCoord.zw));
+ shadow *= 0.25;
+ return shadow;
+}
+
+float Shadow_DoBilinear_2x2(in SHADOWMAP tex, in vec4 projCoord){
+ float border = Shadow_BorderCheck(projCoord.xy);
+ if (border > 0.0)
+ return 1.0;
+
+ ivec2 texSize = textureSize(tex, 0);
+ #ifdef GL_ARB_gpu_shader5
+ vec4 coord = vec4(projCoord.xyz / projCoord.www,0.0);
+ vec4 gather = SHADOWGATHER(tex, coord);
+ #else
+ vec4 gather = vec4(0.0);
+ gather.x = SHADOWCOMPAREOFFSET(tex, projCoord, ivec2(0, 0));
+ gather.y = SHADOWCOMPAREOFFSET(tex, projCoord, ivec2(1, 0));
+ gather.z = SHADOWCOMPAREOFFSET(tex, projCoord, ivec2(0, 1));
+ gather.w = SHADOWCOMPAREOFFSET(tex, projCoord, ivec2(1, 1));
+ #endif
+
+ vec2 f = fract( projCoord.xy * texSize );
+ vec2 mx = mix( gather.xz, gather.yw, f.x );
+ return mix( mx.x, mx.y, f.y );
+}
+
+float Shadow_DoPCF(in SHADOWMAP tex, in vec4 projCoord){
+ float pixSize = 1.0 / textureSize(tex,0).x;
+
+ float shadow = 0.0;
+ float border = Shadow_BorderCheck(projCoord.xy);
+ if (border > 0.0)
+ return 1.0;
+
+ float bound = KERNEL * 0.5 - 0.5;
+ bound *= PCFEDGE;
+ for (float y = -bound; y <= bound; y += PCFEDGE){
+ for (float x = -bound; x <= bound; x += PCFEDGE){
+ vec4 coord = vec4(projCoord.xy + vec2(x,y) * pixSize, projCoord.zw);
+ shadow += SHADOWCOMPARE(tex, coord);
+ }
+ }
+
+ shadow = shadow / (KERNEL * KERNEL);
+ return shadow;
+}
+
+void main(){
+ float shadow = 0.0;
+
+ if(shadowPosition < m_Splits.x){
+ shadow = GETSHADOW(m_ShadowMap0, projCoord0);
+ }else if( shadowPosition < m_Splits.y){
+ shadow = GETSHADOW(m_ShadowMap1, projCoord1);
+ }else if( shadowPosition < m_Splits.z){
+ shadow = GETSHADOW(m_ShadowMap2, projCoord2);
+ }else if( shadowPosition < m_Splits.w){
+ shadow = GETSHADOW(m_ShadowMap3, projCoord3);
+ }
+
+ shadow = shadow * m_ShadowIntensity + (1.0 - m_ShadowIntensity);
+ outFragColor = vec4(shadow, shadow, shadow, 1.0);
+}
+
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag
new file mode 100644
index 0000000..5d957e9
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.frag
@@ -0,0 +1,15 @@
+varying vec2 texCoord;
+
+#ifdef DIFFUSEMAP_ALPHA
+uniform sampler2D m_DiffuseMap;
+#endif
+
+
+void main(){
+ #ifdef DIFFUSEMAP_ALPHA
+ if (texture2D(m_DiffuseMap, texCoord).a <= 0.50)
+ discard;
+ #endif
+
+ gl_FragColor = vec4(1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.j3md b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.j3md
new file mode 100644
index 0000000..070949f
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.j3md
@@ -0,0 +1,19 @@
+MaterialDef Pre Shadow {
+ Technique {
+ VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
+ FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ }
+
+ RenderState {
+ FaceCull Off
+ DepthTest On
+ DepthWrite On
+ PolyOffset 5 0
+ ColorWrite Off
+ }
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.vert b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.vert
new file mode 100644
index 0000000..fdd3a25
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.vert
@@ -0,0 +1,12 @@
+attribute vec4 inPosition;
+attribute vec2 inTexCoord;
+
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform mat4 g_WorldViewMatrix;
+
+varying vec2 texCoord;
+
+void main(){
+ gl_Position = g_WorldViewProjectionMatrix * inPosition;
+ texCoord = inTexCoord;
+} \ No newline at end of file