aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core-effects/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-effects/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-effects/Common/MatDefs')
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/BloomExtract.j3md43
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/BloomFinal.j3md36
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.frag55
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.j3md48
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/CartoonEdge15.frag57
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/CrossHatch.frag51
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/CrossHatch.j3md41
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/CrossHatch15.frag53
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/DepthOfField.frag89
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/DepthOfField.j3md25
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/FXAA.frag88
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/FXAA.j3md20
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/FXAA.vert18
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Fade.frag11
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Fade.j3md34
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Fade15.frag11
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Fog.frag21
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Fog.j3md39
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Fog15.frag24
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.frag23
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.j3md39
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/GammaCorrection15.frag26
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/LightScattering.frag36
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/LightScattering.j3md41
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/LightScattering.vert14
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/LightScattering15.frag39
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/LightScattering15.vert14
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Overlay.frag9
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md36
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Overlay15.frag11
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Post.vert10
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Post15.vert12
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Posterization.frag18
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Posterization.j3md32
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/Posterization15.frag20
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/bloomExtract.frag29
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/bloomExtract15.frag33
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/bloomFinal.frag12
-rw-r--r--engine/src/core-effects/Common/MatDefs/Post/bloomFinal15.frag15
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/Textures/random.pngbin0 -> 42993 bytes
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/normal.frag21
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/normal.vert16
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/ssao.frag104
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/ssao.j3md51
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/ssao15.frag96
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.frag159
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.j3md57
-rw-r--r--engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur15.frag160
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/SimpleWater.j3md34
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Textures/caustics.jpgbin0 -> 57225 bytes
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Textures/dudv_map.jpgbin0 -> 39633 bytes
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Textures/foam.jpgbin0 -> 65823 bytes
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Textures/foam2.jpgbin0 -> 80871 bytes
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Textures/foam3.jpgbin0 -> 100447 bytes
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Textures/heightmap.jpgbin0 -> 24995 bytes
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Textures/water_normalmap.ddsbin0 -> 32896 bytes
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Water.frag402
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Water.j3md90
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/Water15.frag419
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/simple_water.frag126
-rw-r--r--engine/src/core-effects/Common/MatDefs/Water/simple_water.vert87
61 files changed, 3055 insertions, 0 deletions
diff --git a/engine/src/core-effects/Common/MatDefs/Post/BloomExtract.j3md b/engine/src/core-effects/Common/MatDefs/Post/BloomExtract.j3md
new file mode 100644
index 0000000..76614cc
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/BloomExtract.j3md
@@ -0,0 +1,43 @@
+MaterialDef Bloom {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Float ExposurePow
+ Float ExposureCutoff
+ Boolean Extract
+ Texture2D GlowMap
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/bloomExtract15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ HAS_GLOWMAP : GlowMap
+ DO_EXTRACT : Extract
+ RESOLVE_MS : NumSamples
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/bloomExtract.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ HAS_GLOWMAP : GlowMap
+ DO_EXTRACT : Extract
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/BloomFinal.j3md b/engine/src/core-effects/Common/MatDefs/Post/BloomFinal.j3md
new file mode 100644
index 0000000..68f8c28
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/BloomFinal.j3md
@@ -0,0 +1,36 @@
+MaterialDef Bloom Final {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Texture2D BloomTex
+ Float BloomIntensity
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/bloomFinal15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/bloomFinal.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.frag b/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.frag
new file mode 100644
index 0000000..7ee7f78
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.frag
@@ -0,0 +1,55 @@
+uniform vec4 m_EdgeColor;
+
+uniform float m_EdgeWidth;
+uniform float m_EdgeIntensity;
+
+uniform float m_NormalThreshold;
+uniform float m_DepthThreshold;
+
+uniform float m_NormalSensitivity;
+uniform float m_DepthSensitivity;
+
+varying vec2 texCoord;
+
+uniform sampler2D m_Texture;
+uniform sampler2D m_NormalsTexture;
+uniform sampler2D m_DepthTexture;
+
+uniform vec2 g_Resolution;
+
+vec4 fetchNormalDepth(vec2 tc){
+ vec4 nd;
+ nd.xyz = texture2D(m_NormalsTexture, tc).rgb;
+ nd.w = texture2D(m_DepthTexture, tc).r;
+ return nd;
+}
+
+void main(){
+ vec3 color = texture2D(m_Texture, texCoord).rgb;
+
+ vec2 edgeOffset = vec2(m_EdgeWidth) / g_Resolution;
+
+ vec4 n1 = fetchNormalDepth(texCoord + vec2(-1.0, -1.0) * edgeOffset);
+ vec4 n2 = fetchNormalDepth(texCoord + vec2( 1.0, 1.0) * edgeOffset);
+ vec4 n3 = fetchNormalDepth(texCoord + vec2(-1.0, 1.0) * edgeOffset);
+ vec4 n4 = fetchNormalDepth(texCoord + vec2( 1.0, -1.0) * edgeOffset);
+
+ // Work out how much the normal and depth values are changing.
+ vec4 diagonalDelta = abs(n1 - n2) + abs(n3 - n4);
+
+ float normalDelta = dot(diagonalDelta.xyz, vec3(1.0));
+ float depthDelta = diagonalDelta.w;
+
+ // Filter out very small changes, in order to produce nice clean results.
+ normalDelta = clamp((normalDelta - m_NormalThreshold) * m_NormalSensitivity, 0.0, 1.0);
+ depthDelta = clamp((depthDelta - m_DepthThreshold) * m_DepthSensitivity, 0.0, 1.0);
+
+ // Does this pixel lie on an edge?
+ float edgeAmount = clamp(normalDelta + depthDelta, 0.0, 1.0) * m_EdgeIntensity;
+
+ // Apply the edge detection result to the main scene color.
+ //color *= (1.0 - edgeAmount);
+ color = mix (color,m_EdgeColor.rgb,edgeAmount);
+
+ gl_FragColor = vec4(color, 1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.j3md b/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.j3md
new file mode 100644
index 0000000..687193e
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge.j3md
@@ -0,0 +1,48 @@
+MaterialDef Cartoon Edge {
+
+ MaterialParameters {
+ Int NumSamples
+ Int NumSamplesDepth
+ Texture2D Texture
+ Texture2D NormalsTexture
+ Texture2D DepthTexture
+ Color EdgeColor
+ Float EdgeWidth
+ Float EdgeIntensity
+ Float NormalThreshold
+ Float DepthThreshold
+ Float NormalSensitivity
+ Float DepthSensitivity
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/CartoonEdge15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ Resolution
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ RESOLVE_DEPTH_MS : NumSamplesDepth
+ }
+ }
+
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/CartoonEdge.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ Resolution
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge15.frag b/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge15.frag
new file mode 100644
index 0000000..3c3921a
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/CartoonEdge15.frag
@@ -0,0 +1,57 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+uniform DEPTHTEXTURE m_DepthTexture;
+
+uniform sampler2D m_NormalsTexture;
+uniform vec2 g_Resolution;
+
+uniform vec4 m_EdgeColor;
+
+uniform float m_EdgeWidth;
+uniform float m_EdgeIntensity;
+
+uniform float m_NormalThreshold;
+uniform float m_DepthThreshold;
+
+uniform float m_NormalSensitivity;
+uniform float m_DepthSensitivity;
+
+in vec2 texCoord;
+out vec4 outFragColor;
+
+vec4 fetchNormalDepth(vec2 tc){
+ vec4 nd;
+ nd.xyz = texture2D(m_NormalsTexture, tc).rgb;
+ nd.w = fetchTextureSample(m_DepthTexture, tc,0).r;
+ return nd;
+}
+
+void main(){
+ vec3 color = getColor(m_Texture, texCoord).rgb;
+
+ vec2 edgeOffset = vec2(m_EdgeWidth) / textureSize(m_NormalsTexture, 0);
+ vec4 n1 = fetchNormalDepth(texCoord + vec2(-1.0, -1.0) * edgeOffset);
+ vec4 n2 = fetchNormalDepth(texCoord + vec2( 1.0, 1.0) * edgeOffset);
+ vec4 n3 = fetchNormalDepth(texCoord + vec2(-1.0, 1.0) * edgeOffset);
+ vec4 n4 = fetchNormalDepth(texCoord + vec2( 1.0, -1.0) * edgeOffset);
+
+ // Work out how much the normal and depth values are changing.
+ vec4 diagonalDelta = abs(n1 - n2) + abs(n3 - n4);
+
+ float normalDelta = dot(diagonalDelta.xyz, vec3(1.0));
+ float depthDelta = diagonalDelta.w;
+
+ // Filter out very small changes, in order to produce nice clean results.
+ normalDelta = clamp((normalDelta - m_NormalThreshold) * m_NormalSensitivity, 0.0, 1.0);
+ depthDelta = clamp((depthDelta - m_DepthThreshold) * m_DepthSensitivity, 0.0, 1.0);
+
+ // Does this pixel lie on an edge?
+ float edgeAmount = clamp(normalDelta + depthDelta, 0.0, 1.0) * m_EdgeIntensity;
+
+ // Apply the edge detection result to the main scene color.
+ //color *= (1.0 - edgeAmount);
+ color = mix (color,m_EdgeColor.rgb,edgeAmount);
+
+ outFragColor = vec4(color, 1.0);
+}
diff --git a/engine/src/core-effects/Common/MatDefs/Post/CrossHatch.frag b/engine/src/core-effects/Common/MatDefs/Post/CrossHatch.frag
new file mode 100644
index 0000000..fc700f8
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/CrossHatch.frag
@@ -0,0 +1,51 @@
+uniform sampler2D m_Texture;
+varying vec2 texCoord;
+
+uniform vec4 m_LineColor;
+uniform vec4 m_PaperColor;
+uniform float m_ColorInfluenceLine;
+uniform float m_ColorInfluencePaper;
+
+uniform float m_FillValue;
+uniform float m_Luminance1;
+uniform float m_Luminance2;
+uniform float m_Luminance3;
+uniform float m_Luminance4;
+uniform float m_Luminance5;
+
+uniform float m_LineDistance;
+uniform float m_LineThickness;
+
+void main() {
+ vec4 texVal = texture2D(m_Texture, texCoord);
+ float linePixel = 0.0;
+
+ float lum = texVal.r*0.2126 + texVal.g*0.7152 + texVal.b*0.0722;
+
+ if (lum < m_Luminance1){
+ if (mod(gl_FragCoord.x + gl_FragCoord.y, m_LineDistance * 2.0) < m_LineThickness)
+ linePixel = 1.0;
+ }
+ if (lum < m_Luminance2){
+ if (mod(gl_FragCoord.x - gl_FragCoord.y, m_LineDistance * 2.0) < m_LineThickness)
+ linePixel = 1.0;
+ }
+ if (lum < m_Luminance3){
+ if (mod(gl_FragCoord.x + gl_FragCoord.y - m_LineDistance, m_LineDistance) < m_LineThickness)
+ linePixel = 1.0;
+ }
+ if (lum < m_Luminance4){
+ if (mod(gl_FragCoord.x - gl_FragCoord.y - m_LineDistance, m_LineDistance) < m_LineThickness)
+ linePixel = 1.0;
+ }
+ if (lum < m_Luminance5){ // No line, make a blob instead
+ linePixel = m_FillValue;
+ }
+
+ // Mix line color with existing color information
+ vec4 lineColor = mix(m_LineColor, texVal, m_ColorInfluenceLine);
+ // Mix paper color with existing color information
+ vec4 paperColor = mix(m_PaperColor, texVal, m_ColorInfluencePaper);
+
+ gl_FragColor = mix(paperColor, lineColor, linePixel);
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/CrossHatch.j3md b/engine/src/core-effects/Common/MatDefs/Post/CrossHatch.j3md
new file mode 100644
index 0000000..bf850dc
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/CrossHatch.j3md
@@ -0,0 +1,41 @@
+MaterialDef CrossHatch {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture;
+ Vector4 LineColor;
+ Vector4 PaperColor;
+ Float ColorInfluenceLine;
+ Float ColorInfluencePaper;
+ Float FillValue;
+ Float Luminance1;
+ Float Luminance2;
+ Float Luminance3;
+ Float Luminance4;
+ Float Luminance5;
+ Float LineThickness;
+ Float LineDistance;
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/CrossHatch15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/CrossHatch.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/CrossHatch15.frag b/engine/src/core-effects/Common/MatDefs/Post/CrossHatch15.frag
new file mode 100644
index 0000000..8daa4f7
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/CrossHatch15.frag
@@ -0,0 +1,53 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+in vec2 texCoord;
+
+uniform vec4 m_LineColor;
+uniform vec4 m_PaperColor;
+uniform float m_ColorInfluenceLine;
+uniform float m_ColorInfluencePaper;
+
+uniform float m_FillValue;
+uniform float m_Luminance1;
+uniform float m_Luminance2;
+uniform float m_Luminance3;
+uniform float m_Luminance4;
+uniform float m_Luminance5;
+
+uniform float m_LineDistance;
+uniform float m_LineThickness;
+
+void main() {
+ vec4 texVal = getColor(m_Texture, texCoord);
+ float linePixel = 0;
+
+ float lum = texVal.r*0.2126 + texVal.g*0.7152 + texVal.b*0.0722;
+
+ if (lum < m_Luminance1){
+ if (mod(gl_FragCoord.x + gl_FragCoord.y, m_LineDistance * 2.0) < m_LineThickness)
+ linePixel = 1;
+ }
+ if (lum < m_Luminance2){
+ if (mod(gl_FragCoord.x - gl_FragCoord.y, m_LineDistance * 2.0) < m_LineThickness)
+ linePixel = 1;
+ }
+ if (lum < m_Luminance3){
+ if (mod(gl_FragCoord.x + gl_FragCoord.y - m_LineDistance, m_LineDistance) < m_LineThickness)
+ linePixel = 1;
+ }
+ if (lum < m_Luminance4){
+ if (mod(gl_FragCoord.x - gl_FragCoord.y - m_LineDistance, m_LineDistance) < m_LineThickness)
+ linePixel = 1;
+ }
+ if (lum < m_Luminance5){ // No line, make a blob instead
+ linePixel = m_FillValue;
+ }
+
+ // Mix line color with existing color information
+ vec4 lineColor = mix(m_LineColor, texVal, m_ColorInfluenceLine);
+ // Mix paper color with existing color information
+ vec4 paperColor = mix(m_PaperColor, texVal, m_ColorInfluencePaper);
+
+ gl_FragColor = mix(paperColor, lineColor, linePixel);
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/DepthOfField.frag b/engine/src/core-effects/Common/MatDefs/Post/DepthOfField.frag
new file mode 100644
index 0000000..658da54
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/DepthOfField.frag
@@ -0,0 +1,89 @@
+uniform sampler2D m_Texture;
+uniform sampler2D m_DepthTexture;
+varying vec2 texCoord;
+
+uniform float m_FocusRange;
+uniform float m_FocusDistance;
+uniform float m_XScale;
+uniform float m_YScale;
+
+vec2 m_NearFar = vec2( 0.1, 1000.0 );
+
+void main() {
+
+ vec4 texVal = texture2D( m_Texture, texCoord );
+
+ float zBuffer = texture2D( m_DepthTexture, texCoord ).r;
+
+ //
+ // z_buffer_value = a + b / z;
+ //
+ // Where:
+ // a = zFar / ( zFar - zNear )
+ // b = zFar * zNear / ( zNear - zFar )
+ // z = distance from the eye to the object
+ //
+ // Which means:
+ // zb - a = b / z;
+ // z * (zb - a) = b
+ // z = b / (zb - a)
+ //
+ float a = m_NearFar.y / (m_NearFar.y - m_NearFar.x);
+ float b = m_NearFar.y * m_NearFar.x / (m_NearFar.x - m_NearFar.y);
+ float z = b / (zBuffer - a);
+
+ // Above could be the same for any depth-based filter
+
+ // We want to be purely focused right at
+ // m_FocusDistance and be purely unfocused
+ // at +/- m_FocusRange to either side of that.
+ float unfocus = min( 1.0, abs( z - m_FocusDistance ) / m_FocusRange );
+
+ if( unfocus < 0.2 ) {
+ // If we are mostly in focus then don't bother with the
+ // convolution filter
+ gl_FragColor = texVal;
+ } else {
+ // Perform a wide convolution filter and we scatter it
+ // a bit to avoid some texture look-ups. Instead of
+ // a full 5x5 (25-1 lookups) we'll skip every other one
+ // to only perform 12.
+ // 1 0 1 0 1
+ // 0 1 0 1 0
+ // 1 0 x 0 1
+ // 0 1 0 1 0
+ // 1 0 1 0 1
+ //
+ // You can get away with 8 just around the outside but
+ // it looks more jittery to me.
+
+ vec4 sum = vec4(0.0);
+
+ float x = texCoord.x;
+ float y = texCoord.y;
+
+ float xScale = m_XScale;
+ float yScale = m_YScale;
+
+ // In order from lower left to right, depending on how you look at it
+ sum += texture2D( m_Texture, vec2(x - 2.0 * xScale, y - 2.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x - 0.0 * xScale, y - 2.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x + 2.0 * xScale, y - 2.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x - 1.0 * xScale, y - 1.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x + 1.0 * xScale, y - 1.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x - 2.0 * xScale, y - 0.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x + 2.0 * xScale, y - 0.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x - 1.0 * xScale, y + 1.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x + 1.0 * xScale, y + 1.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x - 2.0 * xScale, y + 2.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x - 0.0 * xScale, y + 2.0 * yScale) );
+ sum += texture2D( m_Texture, vec2(x + 2.0 * xScale, y + 2.0 * yScale) );
+
+ sum = sum / 12.0;
+
+ gl_FragColor = mix( texVal, sum, unfocus );
+
+ // I used this for debugging the range
+ // gl_FragColor.r = unfocus;
+}
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/DepthOfField.j3md b/engine/src/core-effects/Common/MatDefs/Post/DepthOfField.j3md
new file mode 100644
index 0000000..db30a09
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/DepthOfField.j3md
@@ -0,0 +1,25 @@
+MaterialDef Depth Of Field {
+
+ MaterialParameters {
+ Int NumSamples
+ Int NumSamplesDepth
+ Texture2D Texture
+ Texture2D DepthTexture
+ Float FocusRange;
+ Float FocusDistance;
+ Float XScale;
+ Float YScale;
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/DepthOfField.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/FXAA.frag b/engine/src/core-effects/Common/MatDefs/Post/FXAA.frag
new file mode 100644
index 0000000..d630b35
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/FXAA.frag
@@ -0,0 +1,88 @@
+#extension GL_EXT_gpu_shader4 : enable
+
+uniform sampler2D m_Texture;
+uniform vec2 g_Resolution;
+
+uniform float m_VxOffset;
+uniform float m_SpanMax;
+uniform float m_ReduceMul;
+
+varying vec2 texCoord;
+varying vec4 posPos;
+
+#define FxaaTex(t, p) texture2D(t, p)
+
+#if __VERSION__ >= 130
+ #define OffsetVec(a, b) ivec2(a, b)
+ #define FxaaTexOff(t, p, o, r) textureOffset(t, p, o)
+#elif defined(GL_EXT_gpu_shader4)
+ #define OffsetVec(a, b) ivec2(a, b)
+ #define FxaaTexOff(t, p, o, r) texture2DLodOffset(t, p, 0.0, o)
+#else
+ #define OffsetVec(a, b) vec2(a, b)
+ #define FxaaTexOff(t, p, o, r) texture2D(t, p + o * r)
+#endif
+
+vec3 FxaaPixelShader(
+ vec4 posPos, // Output of FxaaVertexShader interpolated across screen.
+ sampler2D tex, // Input texture.
+ vec2 rcpFrame) // Constant {1.0/frameWidth, 1.0/frameHeight}.
+{
+
+ #define FXAA_REDUCE_MIN (1.0/128.0)
+ //#define FXAA_REDUCE_MUL (1.0/8.0)
+ //#define FXAA_SPAN_MAX 8.0
+
+ vec3 rgbNW = FxaaTex(tex, posPos.zw).xyz;
+ vec3 rgbNE = FxaaTexOff(tex, posPos.zw, OffsetVec(1,0), rcpFrame.xy).xyz;
+ vec3 rgbSW = FxaaTexOff(tex, posPos.zw, OffsetVec(0,1), rcpFrame.xy).xyz;
+ vec3 rgbSE = FxaaTexOff(tex, posPos.zw, OffsetVec(1,1), rcpFrame.xy).xyz;
+
+ vec3 rgbM = FxaaTex(tex, posPos.xy).xyz;
+
+ vec3 luma = vec3(0.299, 0.587, 0.114);
+ float lumaNW = dot(rgbNW, luma);
+ float lumaNE = dot(rgbNE, luma);
+ float lumaSW = dot(rgbSW, luma);
+ float lumaSE = dot(rgbSE, luma);
+ float lumaM = dot(rgbM, luma);
+
+ float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
+ float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
+
+ vec2 dir;
+ dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
+ dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
+
+ float dirReduce = max(
+ (lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * m_ReduceMul),
+ FXAA_REDUCE_MIN);
+ float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
+ dir = min(vec2( m_SpanMax, m_SpanMax),
+ max(vec2(-m_SpanMax, -m_SpanMax),
+ dir * rcpDirMin)) * rcpFrame.xy;
+
+ vec3 rgbA = (1.0/2.0) * (
+ FxaaTex(tex, posPos.xy + dir * vec2(1.0/3.0 - 0.5)).xyz +
+ FxaaTex(tex, posPos.xy + dir * vec2(2.0/3.0 - 0.5)).xyz);
+ vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (
+ FxaaTex(tex, posPos.xy + dir * vec2(0.0/3.0 - 0.5)).xyz +
+ FxaaTex(tex, posPos.xy + dir * vec2(3.0/3.0 - 0.5)).xyz);
+
+ float lumaB = dot(rgbB, luma);
+
+ if ((lumaB < lumaMin) || (lumaB > lumaMax))
+ {
+ return rgbA;
+ }
+ else
+ {
+ return rgbB;
+ }
+}
+
+void main()
+{
+ vec2 rcpFrame = vec2(1.0) / g_Resolution;
+ gl_FragColor = vec4(FxaaPixelShader(posPos, m_Texture, rcpFrame), 1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/FXAA.j3md b/engine/src/core-effects/Common/MatDefs/Post/FXAA.j3md
new file mode 100644
index 0000000..6685585
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/FXAA.j3md
@@ -0,0 +1,20 @@
+MaterialDef FXAA {
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Float SubPixelShift
+ Float VxOffset
+ Float SpanMax
+ Float ReduceMul
+ }
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/FXAA.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/FXAA.frag
+ WorldParameters {
+ WorldViewProjectionMatrix
+ Resolution
+ }
+ }
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/FXAA.vert b/engine/src/core-effects/Common/MatDefs/Post/FXAA.vert
new file mode 100644
index 0000000..2390384
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/FXAA.vert
@@ -0,0 +1,18 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform vec2 g_Resolution;
+
+uniform float m_SubPixelShift;
+
+attribute vec4 inPosition;
+attribute vec2 inTexCoord;
+
+varying vec2 texCoord;
+varying vec4 posPos;
+
+void main() {
+ gl_Position = inPosition * 2.0 - 1.0; //vec4(pos, 0.0, 1.0);
+ texCoord = inTexCoord;
+ vec2 rcpFrame = vec2(1.0) / g_Resolution;
+ posPos.xy = inTexCoord.xy;
+ posPos.zw = inTexCoord.xy - (rcpFrame * vec2(0.5 + m_SubPixelShift));
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Fade.frag b/engine/src/core-effects/Common/MatDefs/Post/Fade.frag
new file mode 100644
index 0000000..b616239
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Fade.frag
@@ -0,0 +1,11 @@
+uniform sampler2D m_Texture;
+varying vec2 texCoord;
+
+uniform float m_Value;
+
+void main() {
+ vec4 texVal = texture2D(m_Texture, texCoord);
+
+ gl_FragColor = texVal * m_Value;
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Fade.j3md b/engine/src/core-effects/Common/MatDefs/Post/Fade.j3md
new file mode 100644
index 0000000..e93b276
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Fade.j3md
@@ -0,0 +1,34 @@
+MaterialDef Fade {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Float Value
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/Fade15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/Fade.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Fade15.frag b/engine/src/core-effects/Common/MatDefs/Post/Fade15.frag
new file mode 100644
index 0000000..c99de34
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Fade15.frag
@@ -0,0 +1,11 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+uniform float m_Value;
+
+in vec2 texCoord;
+
+void main() {
+ vec4 texVal = getColor(m_Texture, texCoord);
+ gl_FragColor = texVal * m_Value;
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Fog.frag b/engine/src/core-effects/Common/MatDefs/Post/Fog.frag
new file mode 100644
index 0000000..7321b15
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Fog.frag
@@ -0,0 +1,21 @@
+uniform sampler2D m_Texture;
+uniform sampler2D m_DepthTexture;
+varying vec2 texCoord;
+
+uniform vec4 m_FogColor;
+uniform float m_FogDensity;
+uniform float m_FogDistance;
+
+vec2 m_FrustumNearFar=vec2(1.0,m_FogDistance);
+const float LOG2 = 1.442695;
+
+void main() {
+ vec4 texVal = texture2D(m_Texture, texCoord);
+ float fogVal =texture2D(m_DepthTexture,texCoord).r;
+ float depth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - fogVal* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+
+ float fogFactor = exp2( -m_FogDensity * m_FogDensity * depth * depth * LOG2 );
+ fogFactor = clamp(fogFactor, 0.0, 1.0);
+ gl_FragColor =mix(m_FogColor,texVal,fogFactor);
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Fog.j3md b/engine/src/core-effects/Common/MatDefs/Post/Fog.j3md
new file mode 100644
index 0000000..e5d6c8d
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Fog.j3md
@@ -0,0 +1,39 @@
+MaterialDef Fade {
+
+ MaterialParameters {
+ Int NumSamples
+ Int NumSamplesDepth
+ Texture2D Texture
+ Texture2D DepthTexture
+ Vector4 FogColor;
+ Float FogDensity;
+ Float FogDistance;
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/Fog15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ RESOLVE_DEPTH_MS : NumSamplesDepth
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/Fog.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Fog15.frag b/engine/src/core-effects/Common/MatDefs/Post/Fog15.frag
new file mode 100644
index 0000000..65a3407
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Fog15.frag
@@ -0,0 +1,24 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+uniform DEPTHTEXTURE m_DepthTexture;
+
+uniform vec4 m_FogColor;
+uniform float m_FogDensity;
+uniform float m_FogDistance;
+
+in vec2 texCoord;
+
+vec2 m_FrustumNearFar=vec2(1.0,m_FogDistance);
+const float LOG2 = 1.442695;
+
+void main() {
+ vec4 texVal = getColor(m_Texture, texCoord);
+ float fogVal = getDepth(m_DepthTexture,texCoord).r;
+ float depth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - fogVal* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+
+ float fogFactor = exp2( -m_FogDensity * m_FogDensity * depth * depth * LOG2 );
+ fogFactor = clamp(fogFactor, 0.0, 1.0);
+ gl_FragColor =mix(m_FogColor,texVal,fogFactor);
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.frag b/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.frag
new file mode 100644
index 0000000..90b2ade
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.frag
@@ -0,0 +1,23 @@
+uniform sampler2D m_Texture;
+varying vec2 texCoord;
+
+uniform float m_gamma;
+
+vec3 gamma(vec3 L,float gamma)
+{
+ return pow(L, vec3(1.0 / gamma));
+}
+
+void main() {
+ vec4 texVal = texture2D(m_Texture, texCoord);
+
+ if(m_gamma > 0.0)
+ {
+ texVal.rgb = gamma(texVal.rgb , m_gamma);
+ }
+ #ifdef COMPUTE_LUMA
+ texVal.a = dot(texVal.rgb, vec3(0.299, 0.587, 0.114));
+ #endif
+
+ gl_FragColor = texVal;
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.j3md b/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.j3md
new file mode 100644
index 0000000..b9c94c0
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection.j3md
@@ -0,0 +1,39 @@
+MaterialDef GammaCorrection {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Float gamma
+ Boolean computeLuma
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/GammaCorrection15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ COMPUTE_LUMA : computeLuma
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/GammaCorrection.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ COMPUTE_LUMA : computeLuma
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection15.frag b/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection15.frag
new file mode 100644
index 0000000..b786190
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/GammaCorrection15.frag
@@ -0,0 +1,26 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+in vec2 texCoord;
+
+uniform float m_gamma;
+
+vec3 gamma(vec3 L,float gamma)
+{
+ return pow(L, vec3(1.0 / gamma));
+}
+
+void main() {
+ vec4 texVal = texture2D(m_Texture, texCoord);
+
+ if(m_gamma > 0.0)
+ {
+ texVal.rgb = gamma(texVal.rgb , m_gamma);
+ }
+
+ #ifdef COMPUTE_LUMA
+ texVal.a = dot(texVal.rgb, vec3(0.299, 0.587, 0.114));
+ #endif
+
+ gl_FragColor = texVal;
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/LightScattering.frag b/engine/src/core-effects/Common/MatDefs/Post/LightScattering.frag
new file mode 100644
index 0000000..683bbea
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/LightScattering.frag
@@ -0,0 +1,36 @@
+uniform sampler2D m_Texture;
+uniform sampler2D m_DepthTexture;
+uniform int m_NbSamples;
+uniform float m_BlurStart;
+uniform float m_BlurWidth;
+uniform float m_LightDensity;
+uniform bool m_Display;
+
+varying vec2 lightPos;
+varying vec2 texCoord;
+
+void main(void)
+{
+ if(m_Display){
+
+ vec4 colorRes= texture2D(m_Texture,texCoord);
+ float factor=(m_BlurWidth/float(m_NbSamples-1.0));
+ float scale;
+ vec2 texCoo=texCoord-lightPos;
+ vec2 scaledCoord;
+ vec4 res = vec4(0.0);
+ for(int i=0; i<m_NbSamples; i++) {
+ scale = i * factor + m_BlurStart ;
+ scaledCoord=texCoo*scale+lightPos;
+ if(texture2D(m_DepthTexture,scaledCoord).r==1.0){
+ res += texture2D(m_Texture,scaledCoord);
+ }
+ }
+ res /= m_NbSamples;
+
+ //Blend the original color with the averaged pixels
+ gl_FragColor =mix( colorRes, res, m_LightDensity);
+ }else{
+ gl_FragColor= texture2D(m_Texture,texCoord);
+ }
+}
diff --git a/engine/src/core-effects/Common/MatDefs/Post/LightScattering.j3md b/engine/src/core-effects/Common/MatDefs/Post/LightScattering.j3md
new file mode 100644
index 0000000..37e0e85
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/LightScattering.j3md
@@ -0,0 +1,41 @@
+MaterialDef Light Scattering {
+ MaterialParameters {
+ Int NumSamples
+ Int NumSamplesDepth
+ Texture2D Texture
+ Texture2D DepthTexture
+ Vector3 LightPosition
+ Int NbSamples
+ Float BlurStart
+ Float BlurWidth
+ Float LightDensity
+ Boolean Display
+ Boolean multiSampledDepth
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/LightScattering15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/LightScattering15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ RESOLVE_DEPTH_MS : NumSamplesDepth
+ }
+ }
+
+ Technique {
+ VertexShader GLSL120: Common/MatDefs/Post/LightScattering.vert
+ FragmentShader GLSL120: Common/MatDefs/Post/LightScattering.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/LightScattering.vert b/engine/src/core-effects/Common/MatDefs/Post/LightScattering.vert
new file mode 100644
index 0000000..f58f66e
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/LightScattering.vert
@@ -0,0 +1,14 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform vec3 m_LightPosition;
+
+attribute vec4 inPosition;
+attribute vec2 inTexCoord;
+varying vec2 texCoord;
+varying vec2 lightPos;
+
+void main() {
+ vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
+ gl_Position = vec4(pos, 0.0, 1.0);
+ lightPos=m_LightPosition.xy;
+ texCoord = inTexCoord;
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/LightScattering15.frag b/engine/src/core-effects/Common/MatDefs/Post/LightScattering15.frag
new file mode 100644
index 0000000..2a5ae26
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/LightScattering15.frag
@@ -0,0 +1,39 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+uniform DEPTHTEXTURE m_DepthTexture;
+
+uniform int m_NbSamples;
+uniform float m_BlurStart;
+uniform float m_BlurWidth;
+uniform float m_LightDensity;
+uniform bool m_Display;
+
+in vec2 lightPos;
+in vec2 texCoord;
+
+void main(void)
+{
+ if(m_Display){
+
+ vec4 colorRes= getColor(m_Texture,texCoord);
+ float factor=(m_BlurWidth/float(m_NbSamples-1.0));
+ float scale;
+ vec2 texCoo=texCoord-lightPos;
+ vec2 scaledCoord;
+ vec4 res = vec4(0.0);
+ for(int i=0; i<m_NbSamples; i++) {
+ scale = i * factor + m_BlurStart ;
+ scaledCoord=texCoo*scale+lightPos;
+ if(fetchTextureSample(m_DepthTexture, scaledCoord,0).r==1.0){
+ res += fetchTextureSample(m_Texture,scaledCoord,0);
+ }
+ }
+ res /= m_NbSamples;
+
+ //Blend the original color with the averaged pixels
+ gl_FragColor =mix( colorRes, res, m_LightDensity);
+ }else{
+ gl_FragColor= getColor(m_Texture,texCoord);
+ }
+}
diff --git a/engine/src/core-effects/Common/MatDefs/Post/LightScattering15.vert b/engine/src/core-effects/Common/MatDefs/Post/LightScattering15.vert
new file mode 100644
index 0000000..990951b
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/LightScattering15.vert
@@ -0,0 +1,14 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform vec3 m_LightPosition;
+
+in vec4 inPosition;
+in vec2 inTexCoord;
+out vec2 texCoord;
+out vec2 lightPos;
+
+void main() {
+ vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
+ gl_Position = vec4(pos, 0.0, 1.0);
+ lightPos=m_LightPosition.xy;
+ texCoord = inTexCoord;
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Overlay.frag b/engine/src/core-effects/Common/MatDefs/Post/Overlay.frag
new file mode 100644
index 0000000..15d4bcb
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Overlay.frag
@@ -0,0 +1,9 @@
+uniform sampler2D m_Texture;
+uniform vec4 m_Color;
+varying vec2 texCoord;
+
+void main() {
+ vec4 texVal = texture2D(m_Texture, texCoord);
+ gl_FragColor = texVal * m_Color;
+}
+
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md b/engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md
new file mode 100644
index 0000000..fbf2d24
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md
@@ -0,0 +1,36 @@
+MaterialDef Default GUI {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture
+ Color Color
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/Overlay15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ }
+
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/Overlay.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Overlay15.frag b/engine/src/core-effects/Common/MatDefs/Post/Overlay15.frag
new file mode 100644
index 0000000..7dc4d1e
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Overlay15.frag
@@ -0,0 +1,11 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+uniform vec4 m_Color;
+in vec2 texCoord;
+
+void main() {
+ vec4 texVal = getColor(m_Texture, texCoord);
+ gl_FragColor = texVal * m_Color;
+}
+
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Post.vert b/engine/src/core-effects/Common/MatDefs/Post/Post.vert
new file mode 100644
index 0000000..6d80905
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Post.vert
@@ -0,0 +1,10 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+
+attribute vec4 inPosition;
+attribute vec2 inTexCoord;
+varying vec2 texCoord;
+
+void main() {
+ gl_Position = inPosition * 2.0 - 1.0; //vec4(pos, 0.0, 1.0);
+ texCoord = inTexCoord;
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Post15.vert b/engine/src/core-effects/Common/MatDefs/Post/Post15.vert
new file mode 100644
index 0000000..367c330
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Post15.vert
@@ -0,0 +1,12 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+
+in vec4 inPosition;
+in vec2 inTexCoord;
+
+out vec2 texCoord;
+
+void main() {
+ vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy;
+ gl_Position = vec4(pos, 0.0, 1.0);
+ texCoord = inTexCoord;
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Posterization.frag b/engine/src/core-effects/Common/MatDefs/Post/Posterization.frag
new file mode 100644
index 0000000..d184bc6
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Posterization.frag
@@ -0,0 +1,18 @@
+uniform sampler2D m_Texture;
+varying vec2 texCoord;
+
+uniform int m_NumColors;
+uniform float m_Gamma;
+uniform float m_Strength;
+
+void main() {
+ vec4 texVal = texture2D(m_Texture, texCoord);
+
+ texVal = pow(texVal, vec4(m_Gamma));
+ texVal = texVal * vec4(m_NumColors);
+ texVal = floor(texVal);
+ texVal = texVal / vec4(m_NumColors);
+ texVal = pow(texVal, vec4(1.0/m_Gamma));
+
+ gl_FragColor = mix(texture2D(m_Texture, texCoord), texVal, m_Strength);
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Posterization.j3md b/engine/src/core-effects/Common/MatDefs/Post/Posterization.j3md
new file mode 100644
index 0000000..244dcbc
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Posterization.j3md
@@ -0,0 +1,32 @@
+MaterialDef Posterization {
+
+ MaterialParameters {
+ Int NumSamples
+ Texture2D Texture;
+ Int NumColors;
+ Float Gamma;
+ Float Strength;
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/Post/Posterization15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL100: Common/MatDefs/Post/Posterization.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ }
+
+ Technique FixedFunc {
+ }
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/Posterization15.frag b/engine/src/core-effects/Common/MatDefs/Post/Posterization15.frag
new file mode 100644
index 0000000..f55ac5b
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/Posterization15.frag
@@ -0,0 +1,20 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+in vec2 texCoord;
+
+uniform int m_NumColors;
+uniform float m_Gamma;
+uniform float m_Strength;
+
+void main() {
+ vec4 texVal = getColor(m_Texture, texCoord);
+
+ texVal = pow(texVal, vec4(m_Gamma));
+ texVal = texVal * m_NumColors;
+ texVal = floor(texVal);
+ texVal = texVal / m_NumColors;
+ texVal = pow(texVal, vec4(1.0/m_Gamma));
+
+ gl_FragColor = mix(getColor(m_Texture, texCoord), texVal, m_Strength);
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Post/bloomExtract.frag b/engine/src/core-effects/Common/MatDefs/Post/bloomExtract.frag
new file mode 100644
index 0000000..23aa45e
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/bloomExtract.frag
@@ -0,0 +1,29 @@
+uniform float m_ExposurePow;
+uniform float m_ExposureCutoff;
+uniform sampler2D m_Texture;
+
+varying vec2 texCoord;
+
+#ifdef HAS_GLOWMAP
+ uniform sampler2D m_GlowMap;
+#endif
+
+void main(){
+ vec4 color = vec4(0.0);
+ #ifdef DO_EXTRACT
+ color = texture2D( m_Texture, texCoord );
+ if ( (color.r+color.g+color.b)/3.0 < m_ExposureCutoff ) {
+ color = vec4(0.0);
+ }else{
+ color = pow(color,vec4(m_ExposurePow));
+ }
+ #endif
+
+ #ifdef HAS_GLOWMAP
+ vec4 glowColor = texture2D(m_GlowMap, texCoord);
+ glowColor = pow(glowColor, vec4(m_ExposurePow));
+ color += glowColor;
+ #endif
+
+ gl_FragColor = color;
+}
diff --git a/engine/src/core-effects/Common/MatDefs/Post/bloomExtract15.frag b/engine/src/core-effects/Common/MatDefs/Post/bloomExtract15.frag
new file mode 100644
index 0000000..7194f9c
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/bloomExtract15.frag
@@ -0,0 +1,33 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+
+uniform float m_ExposurePow;
+uniform float m_ExposureCutoff;
+
+in vec2 texCoord;
+out vec4 outFragColor;
+
+#ifdef HAS_GLOWMAP
+ uniform sampler2D m_GlowMap;
+#endif
+
+void main(){
+ vec4 color = vec4(0.0);
+ #ifdef DO_EXTRACT
+ color = getColorSingle(m_Texture, texCoord);
+ if ( (color.r + color.g + color.b) / 3.0 >= m_ExposureCutoff ) {
+ color = pow(color, vec4(m_ExposurePow));
+ }else{
+ color = vec4(0.0);
+ }
+ #endif
+
+ #ifdef HAS_GLOWMAP
+ vec4 glowColor = texture2D( m_GlowMap, texCoord );
+ glowColor = pow(glowColor, vec4(m_ExposurePow));
+ color += glowColor;
+ #endif
+
+ outFragColor = color;
+}
diff --git a/engine/src/core-effects/Common/MatDefs/Post/bloomFinal.frag b/engine/src/core-effects/Common/MatDefs/Post/bloomFinal.frag
new file mode 100644
index 0000000..9499e58
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/bloomFinal.frag
@@ -0,0 +1,12 @@
+uniform sampler2D m_Texture;
+uniform sampler2D m_BloomTex;
+uniform float m_BloomIntensity;
+
+varying vec2 texCoord;
+
+void main(){
+ vec4 colorRes = texture2D(m_Texture, texCoord);
+ vec4 bloom = texture2D(m_BloomTex, texCoord);
+ gl_FragColor = bloom * m_BloomIntensity + colorRes;
+}
+
diff --git a/engine/src/core-effects/Common/MatDefs/Post/bloomFinal15.frag b/engine/src/core-effects/Common/MatDefs/Post/bloomFinal15.frag
new file mode 100644
index 0000000..34268c5
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Post/bloomFinal15.frag
@@ -0,0 +1,15 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+
+uniform sampler2D m_BloomTex;
+uniform float m_BloomIntensity;
+
+in vec2 texCoord;
+
+void main(){
+ vec4 colorRes = getColor(m_Texture,texCoord);
+ vec4 bloom = texture2D(m_BloomTex, texCoord);
+ gl_FragColor = bloom * m_BloomIntensity + colorRes;
+}
+
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/Textures/random.png b/engine/src/core-effects/Common/MatDefs/SSAO/Textures/random.png
new file mode 100644
index 0000000..e19b7f5
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/Textures/random.png
Binary files differ
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/normal.frag b/engine/src/core-effects/Common/MatDefs/SSAO/normal.frag
new file mode 100644
index 0000000..289c4c0
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/normal.frag
@@ -0,0 +1,21 @@
+varying vec3 normal;
+varying vec2 texCoord;
+
+
+#ifdef DIFFUSEMAP_ALPHA
+ uniform sampler2D m_DiffuseMap;
+ uniform float m_AlphaDiscardThreshold;
+#endif
+
+void main(void)
+{
+
+ #ifdef DIFFUSEMAP_ALPHA
+ if(texture2D(m_DiffuseMap,texCoord).a<m_AlphaDiscardThreshold){
+ discard;
+ }
+ #endif
+ gl_FragColor = vec4(normal.xy* 0.5 + 0.5,-normal.z* 0.5 + 0.5, 1.0);
+
+}
+
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/normal.vert b/engine/src/core-effects/Common/MatDefs/SSAO/normal.vert
new file mode 100644
index 0000000..24a76cb
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/normal.vert
@@ -0,0 +1,16 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform mat3 g_NormalMatrix;
+
+attribute vec3 inPosition;
+attribute vec3 inNormal;
+attribute vec4 inTexCoord;
+
+varying vec3 normal;
+varying vec2 texCoord;
+
+void main(void)
+{
+ texCoord=inTexCoord.xy;
+ normal = normalize(g_NormalMatrix * inNormal);
+ gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition,1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/ssao.frag b/engine/src/core-effects/Common/MatDefs/SSAO/ssao.frag
new file mode 100644
index 0000000..3cd860d
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/ssao.frag
@@ -0,0 +1,104 @@
+uniform vec2 g_Resolution;
+uniform vec2 m_FrustumNearFar;
+uniform sampler2D m_Texture;
+uniform sampler2D m_Normals;
+uniform sampler2D m_DepthTexture;
+uniform vec3 m_FrustumCorner;
+uniform float m_SampleRadius;
+uniform float m_Intensity;
+uniform float m_Scale;
+uniform float m_Bias;
+uniform bool m_UseOnlyAo;
+uniform bool m_UseAo;
+uniform vec2[4] m_Samples;
+
+varying vec2 texCoord;
+
+float depthv;
+
+vec3 getPosition(in vec2 uv){
+ //Reconstruction from depth
+ depthv =texture2D(m_DepthTexture,uv).r;
+ float depth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - depthv* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+
+ //one frustum corner method
+ float x = mix(-m_FrustumCorner.x, m_FrustumCorner.x, uv.x);
+ float y = mix(-m_FrustumCorner.y, m_FrustumCorner.y, uv.y);
+
+ return depth* vec3(x, y, m_FrustumCorner.z);
+}
+
+vec3 getNormal(in vec2 uv){
+ return normalize(texture2D(m_Normals, uv).xyz * 2.0 - 1.0);
+}
+
+vec2 getRandom(in vec2 uv){
+ float rand=(fract(uv.x*(g_Resolution.x/2.0))*0.25)+(fract(uv.y*(g_Resolution.y/2.0))*0.5);
+ return normalize(vec2(rand,rand));
+}
+
+float doAmbientOcclusion(in vec2 tc, in vec3 pos, in vec3 norm){
+ vec3 diff = getPosition(tc)- pos;
+ vec3 v = normalize(diff);
+ float d = length(diff) * m_Scale;
+
+ return max(0.0, dot(norm, v) - m_Bias) * ( 1.0/(1.0 + d) ) * m_Intensity;
+}
+
+vec4 getColor(in float result){
+
+ if(m_UseOnlyAo){
+ return vec4(result,result,result, 1.0);
+ }
+ if(m_UseAo){
+ return texture2D(m_Texture,texCoord)* vec4(result,result,result, 1.0);
+ }else{
+ return texture2D(m_Texture,texCoord);
+ }
+
+}
+
+vec2 reflection(in vec2 v1,in vec2 v2){
+ vec2 result= 2.0 * dot(v2, v1) * v2;
+ result=v1-result;
+ return result;
+}
+
+
+//const vec2 vec[4] = vec2[4](vec2(1.0,0.0), vec2(-1.0,0.0), vec2(0.0,1.0), vec2(0.0,-1.0));
+void main(){
+
+ float result;
+
+ //vec2 vec[4] = { vec2(1.0, 0.0), vec2(-1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, -1.0) };
+ vec3 position = getPosition(texCoord);
+ //optimization, do not calculate AO if depth is 1
+ if(depthv==1.0){
+ gl_FragColor=getColor(1.0);
+ return;
+ }
+ vec3 normal = getNormal(texCoord);
+ vec2 rand = getRandom(texCoord);
+
+ float ao = 0.0;
+ float rad =m_SampleRadius / position.z;
+
+
+ int iterations = 4;
+ for (int j = 0; j < iterations; ++j){
+ vec2 coord1 = reflection(vec2(m_Samples[j]), vec2(rand)) * vec2(rad,rad);
+ vec2 coord2 = vec2(coord1.x* 0.707 - coord1.y* 0.707, coord1.x* 0.707 + coord1.y* 0.707) ;
+
+ ao += doAmbientOcclusion(texCoord + coord1.xy * 0.25, position, normal);
+ ao += doAmbientOcclusion(texCoord + coord2 * 0.50, position, normal);
+ ao += doAmbientOcclusion(texCoord + coord1.xy * 0.75, position, normal);
+ ao += doAmbientOcclusion(texCoord + coord2 * 1.00, position, normal);
+
+ }
+ ao /= float(iterations) * 4.0;
+ result = 1.0-ao;
+
+ gl_FragColor=getColor(result);
+
+//gl_FragColor=vec4(normal,1.0);
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/ssao.j3md b/engine/src/core-effects/Common/MatDefs/SSAO/ssao.j3md
new file mode 100644
index 0000000..762c1e5
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/ssao.j3md
@@ -0,0 +1,51 @@
+MaterialDef SSAO {
+
+ MaterialParameters {
+ Int NumSamples
+ Int NumSamplesDepth
+ Texture2D Texture
+ Texture2D RandomMap
+ Texture2D Normals
+ Texture2D DepthTexture
+ Vector3 FrustumCorner
+ Float SampleRadius
+ Float Intensity
+ Float Scale
+ Float Bias
+ Vector2 FrustumNearFar
+ Vector2Array Samples
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/SSAO/ssao15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ Resolution
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ RESOLVE_DEPTH_MS : NumSamplesDepth
+ }
+ }
+
+ Technique {
+ VertexShader GLSL120: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL120: Common/MatDefs/SSAO/ssao.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ Resolution
+
+ }
+ }
+
+
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/ssao15.frag b/engine/src/core-effects/Common/MatDefs/SSAO/ssao15.frag
new file mode 100644
index 0000000..de3b846
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/ssao15.frag
@@ -0,0 +1,96 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+uniform DEPTHTEXTURE m_DepthTexture;
+
+uniform vec2 g_Resolution;
+uniform vec2 m_FrustumNearFar;
+uniform sampler2D m_Normals;
+uniform sampler2D m_RandomMap;
+uniform vec3 m_FrustumCorner;
+uniform float m_SampleRadius;
+uniform float m_Intensity;
+uniform float m_Scale;
+uniform float m_Bias;
+uniform vec2[4] m_Samples;
+
+in vec2 texCoord;
+
+float depthv;
+
+vec3 getPosition(in vec2 uv){
+ //Reconstruction from depth
+ depthv =getDepth(m_DepthTexture,uv).r;
+ float depth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - depthv* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+
+ //one frustum corner method
+ float x = mix(-m_FrustumCorner.x, m_FrustumCorner.x, uv.x);
+ float y = mix(-m_FrustumCorner.y, m_FrustumCorner.y, uv.y);
+
+ return depth* vec3(x, y, m_FrustumCorner.z);
+}
+
+vec3 getNormal(in vec2 uv){
+ return normalize(texture2D(m_Normals, uv).xyz * 2.0 - 1.0);
+}
+
+vec2 getRandom(in vec2 uv){
+ //float rand=(fract(uv.x*(g_Resolution.x/2.0))*0.25)+(fract(uv.y*(g_Resolution.y/2.0))*0.5);
+ vec4 rand=texture2D(m_RandomMap,g_Resolution * uv / 128.0 * 3.0)*2.0 -1.0;
+
+ return normalize(rand.xy);
+}
+
+float doAmbientOcclusion(in vec2 tc, in vec3 pos, in vec3 norm){
+ vec3 diff = getPosition(tc)- pos;
+ vec3 v = normalize(diff);
+ float d = length(diff) * m_Scale;
+
+ return max(0.0, dot(norm, v) - m_Bias) * ( 1.0/(1.0 + d) ) * m_Intensity;
+}
+
+
+vec2 reflection(in vec2 v1,in vec2 v2){
+ vec2 result= 2.0 * dot(v2, v1) * v2;
+ result=v1-result;
+ return result;
+}
+
+
+//const vec2 vec[4] = vec2[4](vec2(1.0,0.0), vec2(-1.0,0.0), vec2(0.0,1.0), vec2(0.0,-1.0));
+void main(){
+
+ float result;
+
+ //vec2 vec[4] = { vec2(1.0, 0.0), vec2(-1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, -1.0) };
+ vec3 position = getPosition(texCoord);
+ //optimization, do not calculate AO if depth is 1
+ if(depthv==1.0){
+ gl_FragColor=vec4(1.0);
+ return;
+ }
+ vec3 normal = getNormal(texCoord);
+ vec2 rand = getRandom(texCoord);
+
+ float ao = 0.0;
+ float rad =m_SampleRadius / position.z;
+
+
+ int iterations = 4;
+ for (int j = 0; j < iterations; ++j){
+ vec2 coord1 = reflection(vec2(m_Samples[j]), rand) * vec2(rad,rad);
+ vec2 coord2 = vec2(coord1.x* 0.707 - coord1.y* 0.707, coord1.x* 0.707 + coord1.y* 0.707) ;
+
+ ao += doAmbientOcclusion(texCoord + coord1.xy * 0.25, position, normal);
+ ao += doAmbientOcclusion(texCoord + coord2 * 0.50, position, normal);
+ ao += doAmbientOcclusion(texCoord + coord1.xy * 0.75, position, normal);
+ ao += doAmbientOcclusion(texCoord + coord2 * 1.00, position, normal);
+
+ }
+ ao /= float(iterations) * 4.0;
+ result = 1.0-ao;
+
+ gl_FragColor=vec4(result,result,result, 1.0);
+//gl_FragColor=vec4(depthv,depthv,depthv, 1.0);
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.frag b/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.frag
new file mode 100644
index 0000000..48f4a2f
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.frag
@@ -0,0 +1,159 @@
+uniform sampler2D m_Texture;
+uniform sampler2D m_DepthTexture;
+uniform sampler2D m_SSAOMap;
+uniform vec2 g_Resolution;
+uniform bool m_UseOnlyAo;
+uniform bool m_UseAo;
+uniform float m_XScale;
+uniform float m_YScale;
+uniform vec2 m_FrustumNearFar;
+
+varying vec2 texCoord;
+
+vec4 getColor(vec4 color){
+
+
+ #ifdef USE_ONLY_AO
+ return color;
+ #endif
+ #ifdef USE_AO
+ return texture2D(m_Texture,texCoord)* color;
+ #endif
+
+ return texture2D(m_Texture,texCoord);
+
+}
+
+float readDepth(in vec2 uv){
+ float depthv =texture2D(m_DepthTexture,uv).r;
+ return (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - depthv* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+}
+
+ const float epsilon = 0.005;
+
+
+/*
+ const int kernelSize=7;
+
+ vec4 bilateralFilter() {
+ vec4 color = vec4(0.0);
+
+ vec2 sample;
+ float sum = 0.0;
+ float coefZ;
+ float Zp = readDepth(texCoord);
+
+ for(int i = -(kernelSize-1); i <= (kernelSize-1); i+=2) {
+ for(int j = -(kernelSize-1); j <= (kernelSize-1); j+=2) {
+ sample = texCoord + vec2(i,j) / g_Resolution;
+ float zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ sum += coefZ;
+
+ color += coefZ * texture2D(m_SSAOMap,sample);
+
+ }
+ }
+
+ return color / sum;
+ }
+*/
+
+ vec4 convolutionFilter(){
+ vec4 sum = vec4(0.0);
+
+ float x = texCoord.x;
+ float y = texCoord.y;
+
+ float xScale = m_XScale;
+ float yScale = m_YScale;
+
+ float zsum = 1.0;
+ float Zp =readDepth(texCoord);
+
+
+ vec2 sample = vec2(x - 2.0 * xScale, y - 2.0 * yScale);
+ float zTmp =readDepth(sample);
+ float coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 0.0 * xScale, y - 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 2.0 * xScale, y - 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 1.0 * xScale, y - 1.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 1.0 * xScale, y - 1.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 2.0 * xScale, y - 0.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 2.0 * xScale, y - 0.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 1.0 * xScale, y + 1.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 1.0 * xScale, y + 1.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 2.0 * xScale, y + 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 0.0 * xScale, y + 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 2.0 * xScale, y + 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+
+ return sum / zsum;
+ }
+
+
+ void main(){
+ // float depth =texture2D(m_DepthTexture,uv).r;
+
+ gl_FragColor=getColor(convolutionFilter());
+ // gl_FragColor=getColor(bilateralFilter());
+ // gl_FragColor=texture2D(m_SSAOMap,texCoord);
+
+ } \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.j3md b/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.j3md
new file mode 100644
index 0000000..dcc5e49
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur.j3md
@@ -0,0 +1,57 @@
+MaterialDef SSAOBlur {
+
+ MaterialParameters {
+ Int NumSamples
+ Int NumSamplesDepth
+ Texture2D Texture
+ Texture2D SSAOMap
+ Texture2D DepthTexture
+ Vector2 FrustumNearFar
+ Boolean UseAo
+ Boolean UseOnlyAo
+ Float XScale
+ Float YScale
+ }
+
+ Technique {
+ VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150: Common/MatDefs/SSAO/ssaoBlur15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ Resolution
+ }
+
+ Defines {
+ USE_AO : UseAo
+ USE_ONLY_AO : UseOnlyAo
+ RESOLVE_MS : NumSamples
+ RESOLVE_DEPTH_MS : NumSamplesDepth
+ }
+ }
+
+ Technique {
+ VertexShader GLSL120: Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL120: Common/MatDefs/SSAO/ssaoBlur.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ Resolution
+
+ }
+
+ Defines {
+ USE_AO : UseAo
+ USE_ONLY_AO : UseOnlyAo
+ RESOLVE_MS : NumSamples
+ RESOLVE_DEPTH_MS : NumSamplesDepth
+ }
+ }
+
+
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur15.frag b/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur15.frag
new file mode 100644
index 0000000..e90a76f
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/SSAO/ssaoBlur15.frag
@@ -0,0 +1,160 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+uniform COLORTEXTURE m_Texture;
+uniform DEPTHTEXTURE m_DepthTexture;
+uniform sampler2D m_SSAOMap;
+uniform vec2 g_Resolution;
+uniform bool m_UseOnlyAo;
+uniform bool m_UseAo;
+uniform float m_XScale;
+uniform float m_YScale;
+uniform vec2 m_FrustumNearFar;
+
+in vec2 texCoord;
+
+vec4 getResult(vec4 color){
+
+ #ifdef USE_ONLY_AO
+ return color;
+ #endif
+ #ifdef USE_AO
+ return getColor(m_Texture,texCoord)* color;
+ #endif
+
+ return getColor(m_Texture,texCoord);
+
+}
+
+float readDepth(in vec2 uv){
+ float depthv =fetchTextureSample(m_DepthTexture,uv,0).r;
+ return (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - depthv* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+}
+
+ const float epsilon = 0.005;
+
+
+/*
+ const int kernelSize=7;
+
+ vec4 bilateralFilter() {
+ vec4 color = vec4(0.0);
+
+ vec2 sample;
+ float sum = 0.0;
+ float coefZ;
+ float Zp = readDepth(texCoord);
+
+ for(int i = -(kernelSize-1); i <= (kernelSize-1); i+=2) {
+ for(int j = -(kernelSize-1); j <= (kernelSize-1); j+=2) {
+ sample = texCoord + vec2(i,j) / g_Resolution;
+ float zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ sum += coefZ;
+
+ color += coefZ * texture2D(m_SSAOMap,sample);
+
+ }
+ }
+
+ return color / sum;
+ }
+*/
+
+ vec4 convolutionFilter(){
+ vec4 sum = vec4(0.0);
+
+ float x = texCoord.x;
+ float y = texCoord.y;
+
+ float xScale = m_XScale;
+ float yScale = m_YScale;
+
+ float zsum = 1.0;
+ float Zp =readDepth(texCoord);
+
+
+ vec2 sample = vec2(x - 2.0 * xScale, y - 2.0 * yScale);
+ float zTmp =readDepth(sample);
+ float coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 0.0 * xScale, y - 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 2.0 * xScale, y - 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 1.0 * xScale, y - 1.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 1.0 * xScale, y - 1.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 2.0 * xScale, y - 0.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 2.0 * xScale, y - 0.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 1.0 * xScale, y + 1.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 1.0 * xScale, y + 1.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 2.0 * xScale, y + 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x - 0.0 * xScale, y + 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+ sample = vec2(x + 2.0 * xScale, y + 2.0 * yScale);
+ zTmp =readDepth(sample);
+ coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
+ zsum += coefZ;
+ sum += coefZ* texture2D( m_SSAOMap, sample);
+
+
+ return sum / zsum;
+ }
+
+
+ void main(){
+ // float depth =texture2D(m_DepthTexture,uv).r;
+
+ gl_FragColor=getResult(convolutionFilter());
+ // gl_FragColor=getResult(bilateralFilter());
+ // gl_FragColor=getColor(m_SSAOMap,texCoord);
+
+ } \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Water/SimpleWater.j3md b/engine/src/core-effects/Common/MatDefs/Water/SimpleWater.j3md
new file mode 100644
index 0000000..1288324
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/SimpleWater.j3md
@@ -0,0 +1,34 @@
+MaterialDef Simple Water {
+
+ MaterialParameters {
+ Texture2D water_reflection
+ Texture2D water_refraction
+ Texture2D water_depthmap
+ Texture2D water_normalmap
+ Texture2D water_dudvmap
+ Vector4 waterColor
+ Vector3 lightPos
+ Float time
+ Float waterDepth
+ Vector4 distortionScale
+ Vector4 distortionMix
+ Vector4 texScale
+ Vector2 FrustumNearFar
+ Float waterTransparency
+ }
+
+ Technique {
+ VertexShader GLSL100: Common/MatDefs/Water/simple_water.vert
+ FragmentShader GLSL100: Common/MatDefs/Water/simple_water.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ Resolution
+ CameraPosition
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Textures/caustics.jpg b/engine/src/core-effects/Common/MatDefs/Water/Textures/caustics.jpg
new file mode 100644
index 0000000..fb4f21c
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Textures/caustics.jpg
Binary files differ
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Textures/dudv_map.jpg b/engine/src/core-effects/Common/MatDefs/Water/Textures/dudv_map.jpg
new file mode 100644
index 0000000..a2734bb
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Textures/dudv_map.jpg
Binary files differ
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Textures/foam.jpg b/engine/src/core-effects/Common/MatDefs/Water/Textures/foam.jpg
new file mode 100644
index 0000000..fc17ac2
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Textures/foam.jpg
Binary files differ
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Textures/foam2.jpg b/engine/src/core-effects/Common/MatDefs/Water/Textures/foam2.jpg
new file mode 100644
index 0000000..ef19b87
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Textures/foam2.jpg
Binary files differ
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Textures/foam3.jpg b/engine/src/core-effects/Common/MatDefs/Water/Textures/foam3.jpg
new file mode 100644
index 0000000..8295b3f
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Textures/foam3.jpg
Binary files differ
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Textures/heightmap.jpg b/engine/src/core-effects/Common/MatDefs/Water/Textures/heightmap.jpg
new file mode 100644
index 0000000..cfb5846
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Textures/heightmap.jpg
Binary files differ
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Textures/water_normalmap.dds b/engine/src/core-effects/Common/MatDefs/Water/Textures/water_normalmap.dds
new file mode 100644
index 0000000..13582e1
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Textures/water_normalmap.dds
Binary files differ
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Water.frag b/engine/src/core-effects/Common/MatDefs/Water/Water.frag
new file mode 100644
index 0000000..928ee22
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Water.frag
@@ -0,0 +1,402 @@
+// Water pixel shader
+// Copyright (C) JMonkeyEngine 3.0
+// by Remy Bouquet (nehon) for JMonkeyEngine 3.0
+// original HLSL version by Wojciech Toman 2009
+
+uniform sampler2D m_HeightMap;
+uniform sampler2D m_Texture;
+uniform sampler2D m_DepthTexture;
+uniform sampler2D m_NormalMap;
+uniform sampler2D m_FoamMap;
+uniform sampler2D m_CausticsMap;
+uniform sampler2D m_ReflectionMap;
+
+uniform mat4 m_ViewProjectionMatrixInverse;
+uniform mat4 m_TextureProjMatrix;
+uniform vec3 m_CameraPosition;
+
+uniform float m_WaterHeight;
+uniform float m_Time;
+uniform float m_WaterTransparency;
+uniform float m_NormalScale;
+uniform float m_R0;
+uniform float m_MaxAmplitude;
+uniform vec3 m_LightDir;
+uniform vec4 m_LightColor;
+uniform float m_ShoreHardness;
+uniform float m_FoamHardness;
+uniform float m_RefractionStrength;
+uniform vec3 m_FoamExistence;
+uniform vec3 m_ColorExtinction;
+uniform float m_Shininess;
+uniform vec4 m_WaterColor;
+uniform vec4 m_DeepWaterColor;
+uniform vec2 m_WindDirection;
+uniform float m_SunScale;
+uniform float m_WaveScale;
+uniform float m_UnderWaterFogDistance;
+uniform float m_CausticsIntensity;
+
+vec2 scale = vec2(m_WaveScale, m_WaveScale);
+float refractionScale = m_WaveScale;
+
+// Modifies 4 sampled normals. Increase first values to have more
+// smaller "waves" or last to have more bigger "waves"
+const vec4 normalModifier = vec4(3.0, 2.0, 4.0, 10.0);
+// Strength of displacement along normal.
+// Strength of displacement along normal.
+uniform float m_ReflectionDisplace;
+// Water transparency along eye vector.
+const float visibility = 3.0;
+// foam intensity
+uniform float m_FoamIntensity ;
+
+varying vec2 texCoord;
+
+mat3 MatrixInverse(in mat3 inMatrix){
+ float det = dot(cross(inMatrix[0], inMatrix[1]), inMatrix[2]);
+ mat3 T = transpose(inMatrix);
+ return mat3(cross(T[1], T[2]),
+ cross(T[2], T[0]),
+ cross(T[0], T[1])) / det;
+}
+
+
+mat3 computeTangentFrame(in vec3 N, in vec3 P, in vec2 UV) {
+ vec3 dp1 = dFdx(P);
+ vec3 dp2 = dFdy(P);
+ vec2 duv1 = dFdx(UV);
+ vec2 duv2 = dFdy(UV);
+
+ // solve the linear system
+ mat3 M = mat3(dp1, dp2, cross(dp1, dp2));
+ //vec3 dp1xdp2 = cross(dp1, dp2);
+ mat3 inverseM = MatrixInverse(M);
+ //mat2x3 inverseM = mat2x3(cross(dp2, dp1xdp2), cross(dp1xdp2, dp1));
+
+ vec3 T = inverseM * vec3(duv1.x, duv2.x, 0.0);
+ vec3 B = inverseM * vec3(duv1.y, duv2.y, 0.0);
+
+ //vec3 T = inverseM * vec2(duv1.x, duv2.x);
+ //vec3 B = inverseM * vec2(duv1.y, duv2.y);
+
+ // construct tangent frame
+ float maxLength = max(length(T), length(B));
+ T = T / maxLength;
+ B = B / maxLength;
+
+ //vec3 tangent = normalize(T);
+ //vec3 binormal = normalize(B);
+
+ return mat3(T, B, N);
+}
+
+float saturate(in float val){
+ return clamp(val,0.0,1.0);
+}
+
+vec3 saturate(in vec3 val){
+ return clamp(val,vec3(0.0),vec3(1.0));
+}
+
+
+vec3 getPosition(in float depth, in vec2 uv){
+ vec4 pos = vec4(uv, depth, 1.0) * 2.0 - 1.0;
+ pos = m_ViewProjectionMatrixInverse * pos;
+ return pos.xyz / pos.w;
+}
+
+// Function calculating fresnel term.
+// - normal - normalized normal vector
+// - eyeVec - normalized eye vector
+float fresnelTerm(in vec3 normal,in vec3 eyeVec){
+ float angle = 1.0 - saturate(dot(normal, eyeVec));
+ float fresnel = angle * angle;
+ fresnel = fresnel * fresnel;
+ fresnel = fresnel * angle;
+ return saturate(fresnel * (1.0 - saturate(m_R0)) + m_R0 - m_RefractionStrength);
+}
+
+vec2 m_FrustumNearFar=vec2(1.0,m_UnderWaterFogDistance);
+const float LOG2 = 1.442695;
+
+vec4 underWater(){
+
+
+ float sceneDepth = texture2D(m_DepthTexture, texCoord).r;
+ vec3 color2 = texture2D(m_Texture, texCoord).rgb;
+
+ vec3 position = getPosition(sceneDepth, texCoord);
+ float level = m_WaterHeight;
+
+ vec3 eyeVec = position - m_CameraPosition;
+
+ // Find intersection with water surface
+ vec3 eyeVecNorm = normalize(eyeVec);
+ float t = (level - m_CameraPosition.y) / eyeVecNorm.y;
+ vec3 surfacePoint = m_CameraPosition + eyeVecNorm * t;
+
+ vec2 texC = vec2(0.0);
+
+ float cameraDepth = length(m_CameraPosition - surfacePoint);
+ texC = (surfacePoint.xz + eyeVecNorm.xz) * scale + m_Time * 0.03 * m_WindDirection;
+ float bias = texture2D(m_HeightMap, texC).r;
+ level += bias * m_MaxAmplitude;
+ t = (level - m_CameraPosition.y) / eyeVecNorm.y;
+ surfacePoint = m_CameraPosition + eyeVecNorm * t;
+ eyeVecNorm = normalize(m_CameraPosition - surfacePoint);
+
+ // Find normal of water surface
+ float normal1 = texture2D(m_HeightMap, (texC + vec2(-1.0, 0.0) / 256.0)).r;
+ float normal2 = texture2D(m_HeightMap, (texC + vec2(1.0, 0.0) / 256.0)).r;
+ float normal3 = texture2D(m_HeightMap, (texC + vec2(0.0, -1.0) / 256.0)).r;
+ float normal4 = texture2D(m_HeightMap, (texC + vec2(0.0, 1.0) / 256.0)).r;
+
+ vec3 myNormal = normalize(vec3((normal1 - normal2) * m_MaxAmplitude,m_NormalScale,(normal3 - normal4) * m_MaxAmplitude));
+ vec3 normal = myNormal*-1.0;
+ float fresnel = fresnelTerm(normal, eyeVecNorm);
+
+ vec3 refraction = color2;
+ #ifdef ENABLE_REFRACTION
+ texC = texCoord.xy *sin (fresnel+1.0);
+ refraction = texture2D(m_Texture, texC).rgb;
+ #endif
+
+ float waterCol = saturate(length(m_LightColor.rgb) / m_SunScale);
+ refraction = mix(mix(refraction, m_DeepWaterColor.rgb * waterCol, m_WaterTransparency), m_WaterColor.rgb* waterCol,m_WaterTransparency);
+
+ vec3 foam = vec3(0.0);
+ #ifdef ENABLE_FOAM
+ texC = (surfacePoint.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.05 * m_WindDirection + sin(m_Time * 0.001 + position.x) * 0.005;
+ vec2 texCoord2 = (surfacePoint.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.1 * m_WindDirection + sin(m_Time * 0.001 + position.z) * 0.005;
+
+ if(m_MaxAmplitude - m_FoamExistence.z> 0.0001){
+ foam += ((texture2D(m_FoamMap, texC) + texture2D(m_FoamMap, texCoord2)) * m_FoamIntensity * m_FoamIntensity * 0.3 *
+ saturate((level - (m_WaterHeight + m_FoamExistence.z)) / (m_MaxAmplitude - m_FoamExistence.z))).rgb;
+ }
+ foam *= m_LightColor.rgb;
+ #endif
+
+
+
+ vec3 specular = vec3(0.0);
+ vec3 color ;
+ float fogFactor;
+
+ if(position.y>level){
+ #ifdef ENABLE_SPECULAR
+ if(step(0.9999,sceneDepth)==1.0){
+ vec3 lightDir=normalize(m_LightDir);
+ vec3 mirrorEye = (2.0 * dot(eyeVecNorm, normal) * normal - eyeVecNorm);
+ float dotSpec = saturate(dot(mirrorEye.xyz, -lightDir) * 0.5 + 0.5);
+ specular = vec3((1.0 - fresnel) * saturate(-lightDir.y) * ((pow(dotSpec, 512.0)) * (m_Shininess * 1.8 + 0.2)));
+ specular += specular * 25.0 * saturate(m_Shininess - 0.05);
+ specular=specular * m_LightColor.rgb * 100.0;
+ }
+ #endif
+ float fogIntensity= 8.0 * m_WaterTransparency;
+ fogFactor = exp2( -fogIntensity * fogIntensity * cameraDepth * 0.03 * LOG2 );
+ fogFactor = clamp(fogFactor, 0.0, 1.0);
+ color =mix(m_DeepWaterColor.rgb,refraction,fogFactor);
+ specular=specular*fogFactor;
+ color = saturate(color + max(specular, foam ));
+ }else{
+ vec3 caustics = vec3(0.0);
+ #ifdef ENABLE_CAUSTICS
+ vec2 windDirection=m_WindDirection;
+ texC = (position.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.05 * windDirection + sin(m_Time + position.x) * 0.01;
+ vec2 texCoord2 = (position.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.05 * windDirection + sin(m_Time + position.z) * 0.01;
+ caustics += (texture2D(m_CausticsMap, texC)+ texture2D(m_CausticsMap, texCoord2)).rgb;
+ caustics=saturate(mix(m_WaterColor.rgb,caustics,m_CausticsIntensity));
+ color=mix(color2,caustics,m_CausticsIntensity);
+ #else
+ color=color2;
+ #endif
+
+ float fogDepth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - sceneDepth* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+ float fogIntensity= 18 * m_WaterTransparency;
+ fogFactor = exp2( -fogIntensity * fogIntensity * fogDepth * fogDepth * LOG2 );
+ fogFactor = clamp(fogFactor, 0.0, 1.0);
+ color =mix(m_DeepWaterColor.rgb,color,fogFactor);
+ }
+
+ return vec4(color, 1.0);
+}
+
+void main(){
+ float sceneDepth = texture2D(m_DepthTexture, texCoord).r;
+ float isAtFarPlane = step(0.99998, sceneDepth);
+
+ vec3 color2 = texture2D(m_Texture, texCoord).rgb;
+ vec3 color = color2;
+
+ vec3 position = getPosition(sceneDepth,texCoord);
+
+ float level = m_WaterHeight;
+
+ // If we are underwater let's go to under water function
+ if(level >= m_CameraPosition.y){
+ gl_FragColor = underWater();
+ return ;
+ }
+
+ //#ifndef ENABLE_RIPPLES
+ // This optimization won't work on NVIDIA cards if ripples are enabled
+ if(position.y > level + m_MaxAmplitude + isAtFarPlane * 100.0){
+ gl_FragColor = vec4(color2, 1.0);
+ return;
+ }
+ //#endif
+
+ vec3 eyeVec = position - m_CameraPosition;
+ float diff = level - position.y;
+ float cameraDepth = m_CameraPosition.y - position.y;
+
+ // Find intersection with water surface
+ vec3 eyeVecNorm = normalize(eyeVec);
+ float t = (level - m_CameraPosition.y) / eyeVecNorm.y;
+ vec3 surfacePoint = m_CameraPosition + eyeVecNorm * t;
+
+ vec2 texC;
+ int samples = 1;
+ #ifdef ENABLE_HQ_SHORELINE
+ samples = 10;
+ #endif
+ float biasFactor = 1.0/samples;
+ for (int i = 0; i < samples; i++){
+ texC = (surfacePoint.xz + eyeVecNorm.xz * biasFactor) * scale + m_Time * 0.03 * m_WindDirection;
+
+ float bias = texture2D(m_HeightMap, texC).r;
+
+ bias *= biasFactor;
+ level += bias * m_MaxAmplitude;
+ t = (level - m_CameraPosition.y) / eyeVecNorm.y;
+ surfacePoint = m_CameraPosition + eyeVecNorm * t;
+ }
+
+ float depth = length(position - surfacePoint);
+ float depth2 = surfacePoint.y - position.y;
+
+ // XXX: HACK ALERT: Increase water depth to infinity if at far plane
+ // Prevents "foam on horizon" issue
+ // For best results, replace the "100.0" below with the
+ // highest value in the m_ColorExtinction vec3
+ depth += isAtFarPlane * 100.0;
+ depth2 += isAtFarPlane * 100.0;
+
+ eyeVecNorm = normalize(m_CameraPosition - surfacePoint);
+
+ // Find normal of water surface
+ float normal1 = texture2D(m_HeightMap, (texC + vec2(-1.0, 0.0) / 256.0)).r;
+ float normal2 = texture2D(m_HeightMap, (texC + vec2(1.0, 0.0) / 256.0)).r;
+ float normal3 = texture2D(m_HeightMap, (texC + vec2(0.0, -1.0) / 256.0)).r;
+ float normal4 = texture2D(m_HeightMap, (texC + vec2(0.0, 1.0) / 256.0)).r;
+
+ vec3 myNormal = normalize(vec3((normal1 - normal2) * m_MaxAmplitude,m_NormalScale,(normal3 - normal4) * m_MaxAmplitude));
+ vec3 normal = vec3(0.0);
+
+ #ifdef ENABLE_RIPPLES
+ texC = surfacePoint.xz * 0.8 + m_WindDirection * m_Time* 1.6;
+ mat3 tangentFrame = computeTangentFrame(myNormal, eyeVecNorm, texC);
+ vec3 normal0a = normalize(tangentFrame*(2.0 * texture2D(m_NormalMap, texC).xyz - 1.0));
+
+ texC = surfacePoint.xz * 0.4 + m_WindDirection * m_Time* 0.8;
+ tangentFrame = computeTangentFrame(myNormal, eyeVecNorm, texC);
+ vec3 normal1a = normalize(tangentFrame*(2.0 * texture2D(m_NormalMap, texC).xyz - 1.0));
+
+ texC = surfacePoint.xz * 0.2 + m_WindDirection * m_Time * 0.4;
+ tangentFrame = computeTangentFrame(myNormal, eyeVecNorm, texC);
+ vec3 normal2a = normalize(tangentFrame*(2.0 * texture2D(m_NormalMap, texC).xyz - 1.0));
+
+ texC = surfacePoint.xz * 0.1 + m_WindDirection * m_Time * 0.2;
+ tangentFrame = computeTangentFrame(myNormal, eyeVecNorm, texC);
+ vec3 normal3a = normalize(tangentFrame*(2.0 * texture2D(m_NormalMap, texC).xyz - 1.0));
+
+ normal = normalize(normal0a * normalModifier.x + normal1a * normalModifier.y +normal2a * normalModifier.z + normal3a * normalModifier.w);
+ // XXX: Here's another way to fix the terrain edge issue,
+ // But it requires GLSL 1.3 and still looks kinda incorrect
+ // around edges
+ // To make the shader 1.2 compatible we use a trick :
+ // we clamp the x value of the normal and compare it to it's former value instead of using isnan.
+ normal = clamp(normal.x,0.0,1.0)!=normal.x ? myNormal : normal;
+ //if (position.y > level){
+ // gl_FragColor = vec4(color2 + normal*0.0001, 1.0);
+ // return;
+ //}
+ #else
+ normal = myNormal;
+ #endif
+
+ vec3 refraction = color2;
+ #ifdef ENABLE_REFRACTION
+ texC = texCoord.xy;
+ texC += sin(m_Time*1.8 + 3.0 * abs(position.y)) * (refractionScale * min(depth2, 1.0));
+ refraction = texture2D(m_Texture, texC).rgb;
+ #endif
+
+ vec3 waterPosition = surfacePoint.xyz;
+ waterPosition.y -= (level - m_WaterHeight);
+ vec4 texCoordProj = m_TextureProjMatrix * vec4(waterPosition, 1.0);
+
+ texCoordProj.x = texCoordProj.x + m_ReflectionDisplace * normal.x;
+ texCoordProj.z = texCoordProj.z + m_ReflectionDisplace * normal.z;
+ texCoordProj /= texCoordProj.w;
+ texCoordProj.y = 1.0 - texCoordProj.y;
+
+ vec3 reflection = texture2D(m_ReflectionMap, texCoordProj.xy).rgb;
+
+ float fresnel = fresnelTerm(normal, eyeVecNorm);
+
+ float depthN = depth * m_WaterTransparency;
+ float waterCol = saturate(length(m_LightColor.rgb) / m_SunScale);
+ refraction = mix(mix(refraction, m_WaterColor.rgb * waterCol, saturate(depthN / visibility)),
+ m_DeepWaterColor.rgb * waterCol, saturate(depth2 / m_ColorExtinction));
+
+ vec3 foam = vec3(0.0);
+ #ifdef ENABLE_FOAM
+ texC = (surfacePoint.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.05 * m_WindDirection + sin(m_Time * 0.001 + position.x) * 0.005;
+ vec2 texCoord2 = (surfacePoint.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.1 * m_WindDirection + sin(m_Time * 0.001 + position.z) * 0.005;
+
+ if(depth2 < m_FoamExistence.x){
+ foam = (texture2D(m_FoamMap, texC).r + texture2D(m_FoamMap, texCoord2)).rgb * m_FoamIntensity;
+ }else if(depth2 < m_FoamExistence.y){
+ foam = mix((texture2D(m_FoamMap, texC) + texture2D(m_FoamMap, texCoord2)) * m_FoamIntensity, vec4(0.0),
+ (depth2 - m_FoamExistence.x) / (m_FoamExistence.y - m_FoamExistence.x)).rgb;
+ }
+
+ if(m_MaxAmplitude - m_FoamExistence.z > 0.0001){
+ foam += ((texture2D(m_FoamMap, texC) + texture2D(m_FoamMap, texCoord2)) * m_FoamIntensity * m_FoamIntensity * 0.3 *
+ saturate((level - (m_WaterHeight + m_FoamExistence.z)) / (m_MaxAmplitude - m_FoamExistence.z))).rgb;
+ }
+ foam *= m_LightColor.rgb;
+ #endif
+
+ vec3 specular =vec3(0.0);
+ #ifdef ENABLE_SPECULAR
+ vec3 lightDir=normalize(m_LightDir);
+ vec3 mirrorEye = (2.0 * dot(eyeVecNorm, normal) * normal - eyeVecNorm);
+ float dotSpec = saturate(dot(mirrorEye.xyz, -lightDir) * 0.5 + 0.5);
+ specular = vec3((1.0 - fresnel) * saturate(-lightDir.y) * ((pow(dotSpec, 512.0)) * (m_Shininess * 1.8 + 0.2)));
+ specular += specular * 25.0 * saturate(m_Shininess - 0.05);
+ //foam does not shine
+ specular=specular * m_LightColor.rgb - (5.0 * foam);
+ #endif
+
+ color = mix(refraction, reflection, fresnel);
+ color = mix(refraction, color, saturate(depth * m_ShoreHardness));
+ color = saturate(color + max(specular, foam ));
+ color = mix(refraction, color, saturate(depth* m_FoamHardness));
+
+
+ // XXX: HACK ALERT:
+ // We trick the GeForces to think they have
+ // to calculate the derivatives for all these pixels by using step()!
+ // That way we won't get pixels around the edges of the terrain,
+ // Where the derivatives are undefined
+ if(position.y > level){
+ color = color2;
+ }
+
+ gl_FragColor = vec4(color,1.0);
+
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Water.j3md b/engine/src/core-effects/Common/MatDefs/Water/Water.j3md
new file mode 100644
index 0000000..160cadb
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Water.j3md
@@ -0,0 +1,90 @@
+MaterialDef Advanced Water {
+
+ MaterialParameters {
+ Int NumSamples
+ Int NumSamplesDepth
+ Texture2D FoamMap
+ Texture2D CausticsMap
+ Texture2D NormalMap
+ Texture2D ReflectionMap
+ Texture2D HeightMap
+ Texture2D Texture
+ Texture2D DepthTexture
+ Vector3 CameraPosition
+ Float Time
+ Vector3 frustumCorner
+ Matrix4 TextureProjMatrix
+ Matrix4 ViewProjectionMatrixInverse
+ Float WaterHeight
+ Vector3 LightDir
+ Float WaterTransparency
+ Float NormalScale
+ Float R0
+ Float MaxAmplitude
+ Color LightColor
+ Float ShoreHardness
+ Float FoamHardness
+ Float RefractionStrength
+ Float WaveScale
+ Vector3 FoamExistence
+ Float SunScale
+ Vector3 ColorExtinction
+ Float Shininess
+ Color WaterColor
+ Color DeepWaterColor
+ Vector2 WindDirection
+ Float ReflectionDisplace
+ Float FoamIntensity
+ Float CausticsIntensity
+ Float UnderWaterFogDistance
+
+ Boolean UseRipples
+ Boolean UseHQShoreline
+ Boolean UseSpecular
+ Boolean UseFoam
+ Boolean UseCaustics
+ Boolean UseRefraction
+
+ }
+
+ Technique {
+ VertexShader GLSL150 : Common/MatDefs/Post/Post15.vert
+ FragmentShader GLSL150 : Common/MatDefs/Water/Water15.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+
+ Defines {
+ RESOLVE_MS : NumSamples
+ RESOLVE_DEPTH_MS : NumSamplesDepth
+ ENABLE_RIPPLES : UseRipples
+ ENABLE_HQ_SHORELINE : UseHQShoreline
+ ENABLE_SPECULAR : UseSpecular
+ ENABLE_FOAM : UseFoam
+ ENABLE_CAUSTICS : UseCaustics
+ ENABLE_REFRACTION : UseRefraction
+ }
+ }
+
+ Technique {
+ VertexShader GLSL100 : Common/MatDefs/Post/Post.vert
+ FragmentShader GLSL120 : Common/MatDefs/Water/Water.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ }
+ Defines {
+ ENABLE_RIPPLES : UseRipples
+ ENABLE_HQ_SHORELINE : UseHQShoreline
+ ENABLE_SPECULAR : UseSpecular
+ ENABLE_FOAM : UseFoam
+ ENABLE_CAUSTICS : UseCaustics
+ ENABLE_REFRACTION : UseRefraction
+
+ }
+ }
+
+ Technique FixedFunc {
+ }
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Water/Water15.frag b/engine/src/core-effects/Common/MatDefs/Water/Water15.frag
new file mode 100644
index 0000000..64cf280
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/Water15.frag
@@ -0,0 +1,419 @@
+#import "Common/ShaderLib/MultiSample.glsllib"
+
+// Water pixel shader
+// Copyright (C) JMonkeyEngine 3.0
+// by Remy Bouquet (nehon) for JMonkeyEngine 3.0
+// original HLSL version by Wojciech Toman 2009
+
+uniform COLORTEXTURE m_Texture;
+uniform DEPTHTEXTURE m_DepthTexture;
+
+
+uniform sampler2D m_HeightMap;
+uniform sampler2D m_NormalMap;
+uniform sampler2D m_FoamMap;
+uniform sampler2D m_CausticsMap;
+uniform sampler2D m_ReflectionMap;
+
+uniform mat4 m_ViewProjectionMatrixInverse;
+uniform mat4 m_TextureProjMatrix;
+uniform vec3 m_CameraPosition;
+
+uniform float m_WaterHeight;
+uniform float m_Time;
+uniform float m_WaterTransparency;
+uniform float m_NormalScale;
+uniform float m_R0;
+uniform float m_MaxAmplitude;
+uniform vec3 m_LightDir;
+uniform vec4 m_LightColor;
+uniform float m_ShoreHardness;
+uniform float m_FoamHardness;
+uniform float m_RefractionStrength;
+uniform vec3 m_FoamExistence;
+uniform vec3 m_ColorExtinction;
+uniform float m_Shininess;
+uniform vec4 m_WaterColor;
+uniform vec4 m_DeepWaterColor;
+uniform vec2 m_WindDirection;
+uniform float m_SunScale;
+uniform float m_WaveScale;
+uniform float m_UnderWaterFogDistance;
+uniform float m_CausticsIntensity;
+
+
+vec2 scale = vec2(m_WaveScale, m_WaveScale);
+float refractionScale = m_WaveScale;
+
+// Modifies 4 sampled normals. Increase first values to have more
+// smaller "waves" or last to have more bigger "waves"
+const vec4 normalModifier = vec4(3.0, 2.0, 4.0, 10.0);
+// Strength of displacement along normal.
+uniform float m_ReflectionDisplace;
+// Water transparency along eye vector.
+const float visibility = 3.0;
+// foam intensity
+uniform float m_FoamIntensity ;
+
+in vec2 texCoord;
+out vec4 outFragColor;
+
+mat3 MatrixInverse(in mat3 inMatrix){
+ float det = dot(cross(inMatrix[0], inMatrix[1]), inMatrix[2]);
+ mat3 T = transpose(inMatrix);
+ return mat3(cross(T[1], T[2]),
+ cross(T[2], T[0]),
+ cross(T[0], T[1])) / det;
+}
+
+
+mat3 computeTangentFrame(in vec3 N, in vec3 P, in vec2 UV) {
+ vec3 dp1 = dFdx(P);
+ vec3 dp2 = dFdy(P);
+ vec2 duv1 = dFdx(UV);
+ vec2 duv2 = dFdy(UV);
+
+ // solve the linear system
+ vec3 dp1xdp2 = cross(dp1, dp2);
+ mat2x3 inverseM = mat2x3(cross(dp2, dp1xdp2), cross(dp1xdp2, dp1));
+
+ vec3 T = inverseM * vec2(duv1.x, duv2.x);
+ vec3 B = inverseM * vec2(duv1.y, duv2.y);
+
+ // construct tangent frame
+ float maxLength = max(length(T), length(B));
+ T = T / maxLength;
+ B = B / maxLength;
+
+ return mat3(T, B, N);
+}
+
+float saturate(in float val){
+ return clamp(val,0.0,1.0);
+}
+
+vec3 saturate(in vec3 val){
+ return clamp(val,vec3(0.0),vec3(1.0));
+}
+
+vec3 getPosition(in float depth, in vec2 uv){
+ vec4 pos = vec4(uv, depth, 1.0) * 2.0 - 1.0;
+ pos = m_ViewProjectionMatrixInverse * pos;
+ return pos.xyz / pos.w;
+}
+
+// Function calculating fresnel term.
+// - normal - normalized normal vector
+// - eyeVec - normalized eye vector
+float fresnelTerm(in vec3 normal,in vec3 eyeVec){
+ float angle = 1.0 - max(0.0, dot(normal, eyeVec));
+ float fresnel = angle * angle;
+ fresnel = fresnel * fresnel;
+ fresnel = fresnel * angle;
+ return saturate(fresnel * (1.0 - saturate(m_R0)) + m_R0 - m_RefractionStrength);
+}
+
+vec2 m_FrustumNearFar=vec2(1.0,m_UnderWaterFogDistance);
+const float LOG2 = 1.442695;
+
+vec4 underWater(int sampleNum){
+
+
+ float sceneDepth = fetchTextureSample(m_DepthTexture, texCoord, sampleNum).r;
+ vec3 color2 = fetchTextureSample(m_Texture, texCoord, sampleNum).rgb;
+
+ vec3 position = getPosition(sceneDepth, texCoord);
+ float level = m_WaterHeight;
+
+ vec3 eyeVec = position - m_CameraPosition;
+
+ // Find intersection with water surface
+ vec3 eyeVecNorm = normalize(eyeVec);
+ float t = (level - m_CameraPosition.y) / eyeVecNorm.y;
+ vec3 surfacePoint = m_CameraPosition + eyeVecNorm * t;
+
+ vec2 texC = vec2(0.0);
+
+ float cameraDepth = length(m_CameraPosition - surfacePoint);
+ texC = (surfacePoint.xz + eyeVecNorm.xz) * scale + m_Time * 0.03 * m_WindDirection;
+ float bias = texture(m_HeightMap, texC).r;
+ level += bias * m_MaxAmplitude;
+ t = (level - m_CameraPosition.y) / eyeVecNorm.y;
+ surfacePoint = m_CameraPosition + eyeVecNorm * t;
+ eyeVecNorm = normalize(m_CameraPosition - surfacePoint);
+
+ // Find normal of water surface
+ float normal1 = textureOffset(m_HeightMap, texC, ivec2(-1.0, 0.0)).r;
+ float normal2 = textureOffset(m_HeightMap, texC, ivec2( 1.0, 0.0)).r;
+ float normal3 = textureOffset(m_HeightMap, texC, ivec2( 0.0, -1.0)).r;
+ float normal4 = textureOffset(m_HeightMap, texC, ivec2( 0.0, 1.0)).r;
+
+ vec3 myNormal = normalize(vec3((normal1 - normal2) * m_MaxAmplitude,m_NormalScale,(normal3 - normal4) * m_MaxAmplitude));
+ vec3 normal = myNormal*-1.0;
+ float fresnel = fresnelTerm(normal, eyeVecNorm);
+
+ vec3 refraction = color2;
+ #ifdef ENABLE_REFRACTION
+ texC = texCoord.xy *sin (fresnel+1.0);
+ #ifdef RESOLVE_MS
+ ivec2 iTexC = ivec2(texC * textureSize(m_Texture));
+ refraction = texelFetch(m_Texture, iTexC, sampleNum).rgb;
+ #else
+ ivec2 iTexC = ivec2(texC * textureSize(m_Texture, 0));
+ refraction = texelFetch(m_Texture, iTexC, 0).rgb;
+ #endif
+ #endif
+
+ float waterCol = saturate(length(m_LightColor.rgb) / m_SunScale);
+ refraction = mix(mix(refraction, m_DeepWaterColor.rgb * waterCol, m_WaterTransparency), m_WaterColor.rgb* waterCol,m_WaterTransparency);
+
+ vec3 foam = vec3(0.0);
+ #ifdef ENABLE_FOAM
+ texC = (surfacePoint.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.05 * m_WindDirection + sin(m_Time * 0.001 + position.x) * 0.005;
+ vec2 texCoord2 = (surfacePoint.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.1 * m_WindDirection + sin(m_Time * 0.001 + position.z) * 0.005;
+
+ if(m_MaxAmplitude - m_FoamExistence.z> 0.0001){
+ foam += ((texture2D(m_FoamMap, texC) + texture2D(m_FoamMap, texCoord2)) * m_FoamIntensity * m_FoamIntensity * 0.3 *
+ saturate((level - (m_WaterHeight + m_FoamExistence.z)) / (m_MaxAmplitude - m_FoamExistence.z))).rgb;
+ }
+ foam *= m_LightColor.rgb;
+ #endif
+
+
+
+ vec3 specular = vec3(0.0);
+ vec3 color ;
+ float fogFactor;
+
+ if(position.y>level){
+ #ifdef ENABLE_SPECULAR
+ if(step(0.9999,sceneDepth)==1.0){
+ vec3 lightDir=normalize(m_LightDir);
+ vec3 mirrorEye = (2.0 * dot(eyeVecNorm, normal) * normal - eyeVecNorm);
+ float dotSpec = saturate(dot(mirrorEye.xyz, -lightDir) * 0.5 + 0.5);
+ specular = vec3((1.0 - fresnel) * saturate(-lightDir.y) * ((pow(dotSpec, 512.0)) * (m_Shininess * 1.8 + 0.2)));
+ specular += specular * 25.0 * saturate(m_Shininess - 0.05);
+ specular=specular * m_LightColor.rgb * 100.0;
+ }
+ #endif
+ float fogIntensity= 8.0 * m_WaterTransparency;
+ fogFactor = exp2( -fogIntensity * fogIntensity * cameraDepth * 0.03 * LOG2 );
+ fogFactor = clamp(fogFactor, 0.0, 1.0);
+ color =mix(m_DeepWaterColor.rgb,refraction,fogFactor);
+ specular=specular*fogFactor;
+ color = saturate(color + max(specular, foam ));
+ }else{
+ vec3 caustics = vec3(0.0);
+ #ifdef ENABLE_CAUSTICS
+ vec2 windDirection=m_WindDirection;
+ texC = (position.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.05 * windDirection + sin(m_Time + position.x) * 0.01;
+ vec2 texCoord2 = (position.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.05 * windDirection + sin(m_Time + position.z) * 0.01;
+ caustics += (texture2D(m_CausticsMap, texC)+ texture2D(m_CausticsMap, texCoord2)).rgb;
+ caustics=saturate(mix(m_WaterColor.rgb,caustics,m_CausticsIntensity));
+ color=mix(color2,caustics,m_CausticsIntensity);
+ #else
+ color=color2;
+ #endif
+
+ float fogDepth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - sceneDepth* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+ float fogIntensity= 18 * m_WaterTransparency;
+ fogFactor = exp2( -fogIntensity * fogIntensity * fogDepth * fogDepth * LOG2 );
+ fogFactor = clamp(fogFactor, 0.0, 1.0);
+ color =mix(m_DeepWaterColor.rgb,color,fogFactor);
+ }
+
+ return vec4(color, 1.0);
+}
+// NOTE: This will be called even for single-sampling
+vec4 main_multiSample(int sampleNum){
+ // If we are underwater let's call the underwater function
+ if(m_WaterHeight >= m_CameraPosition.y){
+
+ return underWater(sampleNum);
+ }
+
+ float sceneDepth = fetchTextureSample(m_DepthTexture, texCoord, sampleNum).r;
+ vec3 color2 = fetchTextureSample(m_Texture, texCoord, sampleNum).rgb;
+
+ vec3 color = color2;
+ vec3 position = getPosition(sceneDepth, texCoord);
+
+ float level = m_WaterHeight;
+
+ float isAtFarPlane = step(0.99998, sceneDepth);
+ //#ifndef ENABLE_RIPPLES
+ // This optimization won't work on NVIDIA cards if ripples are enabled
+ if(position.y > level + m_MaxAmplitude + isAtFarPlane * 100.0){
+
+ return vec4(color2, 1.0);
+ }
+ //#endif
+
+ vec3 eyeVec = position - m_CameraPosition;
+ float cameraDepth = m_CameraPosition.y - position.y;
+
+ // Find intersection with water surface
+ vec3 eyeVecNorm = normalize(eyeVec);
+ float t = (level - m_CameraPosition.y) / eyeVecNorm.y;
+ vec3 surfacePoint = m_CameraPosition + eyeVecNorm * t;
+
+ vec2 texC = vec2(0.0);
+ int samples = 1;
+ #ifdef ENABLE_HQ_SHORELINE
+ samples = 10;
+ #endif
+
+ float biasFactor = 1.0 / samples;
+ for (int i = 0; i < samples; i++){
+ texC = (surfacePoint.xz + eyeVecNorm.xz * biasFactor) * scale + m_Time * 0.03 * m_WindDirection;
+
+ float bias = texture(m_HeightMap, texC).r;
+
+ bias *= biasFactor;
+ level += bias * m_MaxAmplitude;
+ t = (level - m_CameraPosition.y) / eyeVecNorm.y;
+ surfacePoint = m_CameraPosition + eyeVecNorm * t;
+ }
+
+ float depth = length(position - surfacePoint);
+ float depth2 = surfacePoint.y - position.y;
+
+ // XXX: HACK ALERT: Increase water depth to infinity if at far plane
+ // Prevents "foam on horizon" issue
+ // For best results, replace the "100.0" below with the
+ // highest value in the m_ColorExtinction vec3
+ depth += isAtFarPlane * 100.0;
+ depth2 += isAtFarPlane * 100.0;
+
+ eyeVecNorm = normalize(m_CameraPosition - surfacePoint);
+
+ // Find normal of water surface
+ float normal1 = textureOffset(m_HeightMap, texC, ivec2(-1.0, 0.0)).r;
+ float normal2 = textureOffset(m_HeightMap, texC, ivec2( 1.0, 0.0)).r;
+ float normal3 = textureOffset(m_HeightMap, texC, ivec2( 0.0, -1.0)).r;
+ float normal4 = textureOffset(m_HeightMap, texC, ivec2( 0.0, 1.0)).r;
+
+ vec3 myNormal = normalize(vec3((normal1 - normal2) * m_MaxAmplitude,m_NormalScale,(normal3 - normal4) * m_MaxAmplitude));
+ vec3 normal = vec3(0.0);
+
+ #ifdef ENABLE_RIPPLES
+ texC = surfacePoint.xz * 0.8 + m_WindDirection * m_Time* 1.6;
+ mat3 tangentFrame = computeTangentFrame(myNormal, eyeVecNorm, texC);
+ vec3 normal0a = normalize(tangentFrame*(2.0 * texture(m_NormalMap, texC).xyz - 1.0));
+
+ texC = surfacePoint.xz * 0.4 + m_WindDirection * m_Time* 0.8;
+ tangentFrame = computeTangentFrame(myNormal, eyeVecNorm, texC);
+ vec3 normal1a = normalize(tangentFrame*(2.0 * texture(m_NormalMap, texC).xyz - 1.0));
+
+ texC = surfacePoint.xz * 0.2 + m_WindDirection * m_Time * 0.4;
+ tangentFrame = computeTangentFrame(myNormal, eyeVecNorm, texC);
+ vec3 normal2a = normalize(tangentFrame*(2.0 * texture(m_NormalMap, texC).xyz - 1.0));
+
+ texC = surfacePoint.xz * 0.1 + m_WindDirection * m_Time * 0.2;
+ tangentFrame = computeTangentFrame(myNormal, eyeVecNorm, texC);
+ vec3 normal3a = normalize(tangentFrame*(2.0 * texture(m_NormalMap, texC).xyz - 1.0));
+
+ normal = normalize(normal0a * normalModifier.x + normal1a * normalModifier.y +normal2a * normalModifier.z + normal3a * normalModifier.w);
+ // XXX: Here's another way to fix the terrain edge issue,
+ // But it requires GLSL 1.3 and still looks kinda incorrect
+ // around edges
+ normal = isnan(normal.x) ? myNormal : normal;
+ //if (position.y > level){
+ // gl_FragColor = vec4(color2 + normal*0.0001, 1.0);
+ // return;
+ //}
+ #else
+ normal = myNormal;
+ #endif
+
+ vec3 refraction = color2;
+ #ifdef ENABLE_REFRACTION
+ // texC = texCoord.xy+ m_ReflectionDisplace * normal.x;
+ texC = texCoord.xy;
+ texC += sin(m_Time*1.8 + 3.0 * abs(position.y)) * (refractionScale * min(depth2, 1.0));
+ #ifdef RESOLVE_MS
+ ivec2 iTexC = ivec2(texC * textureSize(m_Texture));
+ refraction = texelFetch(m_Texture, iTexC, sampleNum).rgb;
+ #else
+ ivec2 iTexC = ivec2(texC * textureSize(m_Texture, 0));
+ refraction = texelFetch(m_Texture, iTexC, 0).rgb;
+ #endif
+ #endif
+
+ vec3 waterPosition = surfacePoint.xyz;
+ waterPosition.y -= (level - m_WaterHeight);
+ vec4 texCoordProj = m_TextureProjMatrix * vec4(waterPosition, 1.0);
+
+ texCoordProj.x = texCoordProj.x + m_ReflectionDisplace * normal.x;
+ texCoordProj.z = texCoordProj.z + m_ReflectionDisplace * normal.z;
+ texCoordProj /= texCoordProj.w;
+ texCoordProj.y = 1.0 - texCoordProj.y;
+
+ vec3 reflection = texture(m_ReflectionMap, texCoordProj.xy).rgb;
+
+ float fresnel = fresnelTerm(normal, eyeVecNorm);
+
+ float depthN = depth * m_WaterTransparency;
+ float waterCol = saturate(length(m_LightColor.rgb) / m_SunScale);
+ refraction = mix(mix(refraction, m_WaterColor.rgb * waterCol, saturate(depthN / visibility)),
+ m_DeepWaterColor.rgb * waterCol, saturate(depth2 / m_ColorExtinction));
+
+
+
+
+ vec3 foam = vec3(0.0);
+ #ifdef ENABLE_FOAM
+ texC = (surfacePoint.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.05 * m_WindDirection + sin(m_Time * 0.001 + position.x) * 0.005;
+ vec2 texCoord2 = (surfacePoint.xz + eyeVecNorm.xz * 0.1) * 0.05 + m_Time * 0.1 * m_WindDirection + sin(m_Time * 0.001 + position.z) * 0.005;
+
+ if(depth2 < m_FoamExistence.x){
+ foam = (texture2D(m_FoamMap, texC).r + texture2D(m_FoamMap, texCoord2)).rgb * vec3(m_FoamIntensity);
+ }else if(depth2 < m_FoamExistence.y){
+ foam = mix((texture2D(m_FoamMap, texC) + texture2D(m_FoamMap, texCoord2)) * m_FoamIntensity , vec4(0.0),
+ (depth2 - m_FoamExistence.x) / (m_FoamExistence.y - m_FoamExistence.x)).rgb;
+ }
+
+
+ if(m_MaxAmplitude - m_FoamExistence.z> 0.0001){
+ foam += ((texture2D(m_FoamMap, texC) + texture2D(m_FoamMap, texCoord2)) * m_FoamIntensity * m_FoamIntensity * 0.3 *
+ saturate((level - (m_WaterHeight + m_FoamExistence.z)) / (m_MaxAmplitude - m_FoamExistence.z))).rgb;
+ }
+ foam *= m_LightColor.rgb;
+ #endif
+
+ vec3 specular = vec3(0.0);
+ #ifdef ENABLE_SPECULAR
+ vec3 lightDir=normalize(m_LightDir);
+ vec3 mirrorEye = (2.0 * dot(eyeVecNorm, normal) * normal - eyeVecNorm);
+ float dotSpec = saturate(dot(mirrorEye.xyz, -lightDir) * 0.5 + 0.5);
+ specular = vec3((1.0 - fresnel) * saturate(-lightDir.y) * ((pow(dotSpec, 512.0)) * (m_Shininess * 1.8 + 0.2)));
+ specular += specular * 25.0 * saturate(m_Shininess - 0.05);
+ //foam does not shine
+ specular=specular * m_LightColor.rgb - (5.0 * foam);
+ #endif
+
+ color = mix(refraction, reflection, fresnel);
+ color = mix(refraction, color, saturate(depth * m_ShoreHardness));
+ color = saturate(color + max(specular, foam ));
+ color = mix(refraction, color, saturate(depth* m_FoamHardness));
+
+
+ // XXX: HACK ALERT:
+ // We trick the GeForces to think they have
+ // to calculate the derivatives for all these pixels by using step()!
+ // That way we won't get pixels around the edges of the terrain,
+ // Where the derivatives are undefined
+ return vec4(mix(color, color2, step(level, position.y)), 1.0);
+}
+
+void main(){
+ #ifdef RESOLVE_MS
+ vec4 color = vec4(0.0);
+ for (int i = 0; i < m_NumSamples; i++){
+ color += main_multiSample(i);
+ }
+ outFragColor = color / m_NumSamples;
+ #else
+ outFragColor = main_multiSample(0);
+ #endif
+} \ No newline at end of file
diff --git a/engine/src/core-effects/Common/MatDefs/Water/simple_water.frag b/engine/src/core-effects/Common/MatDefs/Water/simple_water.frag
new file mode 100644
index 0000000..65a9c99
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/simple_water.frag
@@ -0,0 +1,126 @@
+/*
+GLSL conversion of Michael Horsch water demo
+http://www.bonzaisoftware.com/wfs.html
+Converted by Mars_999
+8/20/2005
+*/
+
+uniform sampler2D m_water_normalmap;
+uniform sampler2D m_water_reflection;
+uniform sampler2D m_water_refraction;
+uniform sampler2D m_water_dudvmap;
+uniform sampler2D m_water_depthmap;
+uniform vec4 m_waterColor;
+uniform float m_waterDepth;
+uniform vec4 m_distortionScale;
+uniform vec4 m_distortionMix;
+uniform vec4 m_texScale;
+uniform vec2 m_FrustumNearFar;
+uniform float m_waterTransparency;
+
+
+
+varying vec4 lightDir; //lightpos
+varying vec4 waterTex1; //moving texcoords
+varying vec4 waterTex2; //moving texcoords
+varying vec4 position; //for projection
+varying vec4 viewDir; //viewts
+varying vec4 viewLightDir;
+varying vec4 viewCamDir;
+
+//unit 0 = m_water_reflection
+//unit 1 = m_water_refraction
+//unit 2 = m_water_normalmap
+//unit 3 = m_water_dudvmap
+//unit 4 = m_water_depthmap
+
+ const vec4 two = vec4(2.0, 2.0, 2.0, 1.0);
+ const vec4 mone = vec4(-1.0, -1.0, -1.0, 1.0);
+
+ const vec4 ofive = vec4(0.5,0.5,0.5,1.0);
+
+ const float exponent = 64.0;
+
+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
+}
+
+vec4 readDepth(vec2 uv){
+ float depth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - texture2D(m_water_depthmap, uv).r* (m_FrustumNearFar.y-m_FrustumNearFar.x));
+ return vec4( depth);
+}
+
+void main(void)
+{
+
+
+ vec4 lightTS = normalize(lightDir);
+ vec4 viewt = normalize(viewDir);
+ vec4 disdis = texture2D(m_water_dudvmap, vec2(waterTex2 * m_texScale));
+ vec4 fdist = texture2D(m_water_dudvmap, vec2(waterTex1 + disdis*m_distortionMix));
+ fdist =normalize( fdist * 2.0 - 1.0)* m_distortionScale;
+
+
+ //load normalmap
+ vec4 nmap = texture2D(m_water_normalmap, vec2(waterTex1 + disdis*m_distortionMix));
+ nmap = (nmap-ofive) * two;
+ // nmap = nmap*2.0-1.0;
+ vec4 vNorm = normalize(nmap);
+
+
+ vec4 projCoord = position / position.w;
+ projCoord =(projCoord+1.0)*0.5 + fdist;
+ projCoord = clamp(projCoord, 0.001, 0.999);
+
+ //load reflection,refraction and depth texture
+ vec4 refl = texture2D(m_water_reflection, vec2(projCoord.x,1.0-projCoord.y));
+ vec4 refr = texture2D(m_water_refraction, vec2(projCoord));
+ vec4 wdepth =readDepth(vec2(projCoord));
+
+ wdepth = vec4(pow(wdepth.x, m_waterDepth));
+ vec4 invdepth = 1.0 - wdepth;
+
+
+ // Blinn - Phong
+ // vec4 H = (viewt - lightTS);
+ // vec4 specular =vec4(pow(max(dot(H, vNorm), 0.0), exponent));
+
+// Standard Phong
+
+ // vec4 R =reflect(-L, vNorm);
+ // vec4 specular =vec4( pow(max(dot(R, E), 0.0),exponent));
+
+
+ //calculate specular highlight
+ vec4 L=normalize(viewLightDir);
+ vec4 E=normalize(viewCamDir);
+ vec4 vRef = normalize(reflect(-L,vNorm));
+ float stemp =max(0.0, dot( vRef,E) );
+ //initializing to 0 to avoid artifacts on old intel cards
+ vec4 specular = vec4(0.0,0.0,0.0,0.0);
+ if(stemp>0.0){
+ stemp = pow(stemp, exponent);
+ specular = vec4(stemp);
+ }
+
+
+
+ vec4 fresnelTerm = vec4(0.02+0.97*pow((1.0-dot(normalize(viewt), vNorm)),5.0));
+
+
+
+ fresnelTerm=fresnelTerm*invdepth*m_waterTransparency;
+ fresnelTerm=clamp(fresnelTerm,0.0,1.0);
+
+ refr*=(fresnelTerm);
+ refr *= invdepth;
+ refr= refr+ m_waterColor*wdepth*fresnelTerm;
+
+ gl_FragColor =(refr+ refl*(1.0-fresnelTerm))+specular;
+}
diff --git a/engine/src/core-effects/Common/MatDefs/Water/simple_water.vert b/engine/src/core-effects/Common/MatDefs/Water/simple_water.vert
new file mode 100644
index 0000000..e6052d8
--- /dev/null
+++ b/engine/src/core-effects/Common/MatDefs/Water/simple_water.vert
@@ -0,0 +1,87 @@
+/*
+GLSL conversion of Michael Horsch water demo
+http://www.bonzaisoftware.com/wfs.html
+Converted by Mars_999
+8/20/2005
+*/
+uniform vec3 m_lightPos;
+uniform float m_time;
+
+uniform mat4 g_WorldViewProjectionMatrix;
+uniform mat4 g_WorldViewMatrix;
+uniform mat4 g_ViewMatrix;
+uniform vec3 g_CameraPosition;
+uniform mat3 g_NormalMatrix;
+
+attribute vec4 inPosition;
+attribute vec2 inTexCoord;
+attribute vec3 inTangent;
+attribute vec3 inNormal;
+
+varying vec4 lightDir;
+varying vec4 waterTex1;
+varying vec4 waterTex2;
+varying vec4 position;
+varying vec4 viewDir;
+varying vec4 viewpos;
+varying vec4 viewLightDir;
+varying vec4 viewCamDir;
+
+
+//unit 0 = water_reflection
+//unit 1 = water_refraction
+//unit 2 = water_normalmap
+//unit 3 = water_dudvmap
+//unit 4 = water_depthmap
+
+void main(void)
+{
+ viewpos.x = g_CameraPosition.x;
+ viewpos.y = g_CameraPosition.y;
+ viewpos.z = g_CameraPosition.z;
+ viewpos.w = 1.0;
+
+ vec4 temp;
+ vec4 tangent = vec4(1.0, 0.0, 0.0, 0.0);
+ vec4 norm = vec4(0.0, 1.0, 0.0, 0.0);
+ vec4 binormal = vec4(0.0, 0.0, 1.0, 0.0);
+
+
+ temp = viewpos - inPosition;
+
+ viewDir.x = dot(temp, tangent);
+ viewDir.y = dot(temp, binormal);
+ viewDir.z = dot(temp, norm);
+ viewDir.w = 0.0;
+
+ temp = vec4(m_lightPos,1.0)- inPosition;
+ lightDir.x = dot(temp, tangent);
+ lightDir.y = dot(temp, binormal);
+ lightDir.z = dot(temp, norm);
+ lightDir.w = 0.0;
+
+ vec4 viewSpaceLightPos=g_ViewMatrix*vec4(m_lightPos,1.0);
+ vec4 viewSpacePos=g_WorldViewMatrix*inPosition;
+ vec3 wvNormal = normalize(g_NormalMatrix * inNormal);
+ vec3 wvTangent = normalize(g_NormalMatrix * inTangent);
+ vec3 wvBinormal = cross(wvNormal, wvTangent);
+ mat3 tbnMat = mat3(wvTangent, wvBinormal, wvNormal);
+
+ temp = viewSpaceLightPos - viewSpacePos;
+ viewLightDir.xyz=temp.xyz*tbnMat;
+ viewLightDir.w = 0.0;
+
+ temp = -viewSpacePos;
+ viewCamDir.xyz =temp.xyz*tbnMat;
+ viewCamDir.w = 0.0;
+
+
+ vec4 t1 = vec4(0.0, -m_time, 0.0,0.0);
+ vec4 t2 = vec4(0.0, m_time, 0.0,0.0);
+
+ waterTex1 =vec4(inTexCoord,0.0,0.0) + t1;
+ waterTex2 =vec4(inTexCoord ,0.0,0.0)+ t2;
+
+ position = g_WorldViewProjectionMatrix * inPosition;
+ gl_Position = position;
+}