]> git.lizzy.rs Git - irrlicht.git/commitdiff
Add shaders for COpenGL3DriverBase
authornumzero <numzer0@yandex.ru>
Sat, 25 Mar 2023 08:05:40 +0000 (11:05 +0300)
committernumzero <numzer0@yandex.ru>
Sat, 25 Mar 2023 08:10:05 +0000 (11:10 +0300)
Currently, they are identical to OGLES2 shaders, except of version specification.

18 files changed:
media/Shaders/DetailMap.fsh [new file with mode: 0644]
media/Shaders/LightmapAdd.fsh [new file with mode: 0644]
media/Shaders/LightmapModulate.fsh [new file with mode: 0644]
media/Shaders/OneTextureBlend.fsh [new file with mode: 0644]
media/Shaders/Reflection2Layer.fsh [new file with mode: 0644]
media/Shaders/Reflection2Layer.vsh [new file with mode: 0644]
media/Shaders/Renderer2D.fsh [new file with mode: 0644]
media/Shaders/Renderer2D.vsh [new file with mode: 0644]
media/Shaders/Renderer2D_noTex.fsh [new file with mode: 0644]
media/Shaders/Solid.fsh [new file with mode: 0644]
media/Shaders/Solid.vsh [new file with mode: 0644]
media/Shaders/Solid2.vsh [new file with mode: 0644]
media/Shaders/Solid2Layer.fsh [new file with mode: 0644]
media/Shaders/SphereMap.fsh [new file with mode: 0644]
media/Shaders/SphereMap.vsh [new file with mode: 0644]
media/Shaders/TransparentAlphaChannel.fsh [new file with mode: 0644]
media/Shaders/TransparentAlphaChannelRef.fsh [new file with mode: 0644]
media/Shaders/TransparentVertexAlpha.fsh [new file with mode: 0644]

diff --git a/media/Shaders/DetailMap.fsh b/media/Shaders/DetailMap.fsh
new file mode 100644 (file)
index 0000000..01c94d7
--- /dev/null
@@ -0,0 +1,72 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage0;
+uniform int uTextureUsage1;
+uniform sampler2D uTextureUnit0;
+uniform sampler2D uTextureUnit1;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec2 vTextureCoord1;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0);
+       vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
+
+       if (bool(uTextureUsage0))
+               Color0 = texture2D(uTextureUnit0, vTextureCoord0);
+
+       if (bool(uTextureUsage1))
+               Color1 = texture2D(uTextureUnit1, vTextureCoord1);
+
+       vec4 FinalColor = vec4(Color0 + (Color1 - 0.5)) * vVertexColor + vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               FinalColor = mix(FogColor, FinalColor, FogFactor);
+       }
+
+       gl_FragColor = FinalColor;
+}
diff --git a/media/Shaders/LightmapAdd.fsh b/media/Shaders/LightmapAdd.fsh
new file mode 100644 (file)
index 0000000..895625f
--- /dev/null
@@ -0,0 +1,72 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage0;
+uniform int uTextureUsage1;
+uniform sampler2D uTextureUnit0;
+uniform sampler2D uTextureUnit1;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec2 vTextureCoord1;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0);
+       vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
+
+       if (bool(uTextureUsage0))
+               Color0 = texture2D(uTextureUnit0, vTextureCoord0);
+
+       if (bool(uTextureUsage1))
+               Color1 = texture2D(uTextureUnit1, vTextureCoord1);
+
+       vec4 FinalColor = (Color0 + Color1) * vVertexColor + vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               FinalColor = mix(FogColor, FinalColor, FogFactor);
+       }
+
+       gl_FragColor = FinalColor;
+}
diff --git a/media/Shaders/LightmapModulate.fsh b/media/Shaders/LightmapModulate.fsh
new file mode 100644 (file)
index 0000000..74e9df1
--- /dev/null
@@ -0,0 +1,74 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform float uModulate;
+uniform int uTextureUsage0;
+uniform int uTextureUsage1;
+uniform sampler2D uTextureUnit0;
+uniform sampler2D uTextureUnit1;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec2 vTextureCoord1;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0);
+       vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
+
+       if (bool(uTextureUsage0))
+               Color0 = texture2D(uTextureUnit0, vTextureCoord0);
+
+       if (bool(uTextureUsage1))
+               Color1 = texture2D(uTextureUnit1, vTextureCoord1);
+
+       vec4 FinalColor = (Color0 * Color1 * uModulate) * vVertexColor;
+       FinalColor += vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               FinalColor = mix(FogColor, FinalColor, FogFactor);
+       }
+
+       gl_FragColor = FinalColor;
+}
diff --git a/media/Shaders/OneTextureBlend.fsh b/media/Shaders/OneTextureBlend.fsh
new file mode 100644 (file)
index 0000000..c348016
--- /dev/null
@@ -0,0 +1,77 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage0;
+uniform sampler2D uTextureUnit0;
+uniform int uBlendType;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color0 = vVertexColor;
+       vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
+
+       if (bool(uTextureUsage0))
+               Color1 = texture2D(uTextureUnit0, vTextureCoord0);
+
+       vec4 FinalColor = Color0 * Color1;
+       FinalColor += vSpecularColor;
+
+       if (uBlendType == 1)
+       {
+               FinalColor.w = Color0.w;
+       }
+       else if (uBlendType == 2)
+       {
+               FinalColor.w = Color1.w;
+       }
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               FinalColor = mix(FogColor, FinalColor, FogFactor);
+       }
+
+       gl_FragColor = FinalColor;
+}
diff --git a/media/Shaders/Reflection2Layer.fsh b/media/Shaders/Reflection2Layer.fsh
new file mode 100644 (file)
index 0000000..bdc3c66
--- /dev/null
@@ -0,0 +1,72 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage0;
+uniform int uTextureUsage1;
+uniform sampler2D uTextureUnit0;
+uniform sampler2D uTextureUnit1;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec2 vTextureCoord1;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0);
+       vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
+
+       if (bool(uTextureUsage0))
+               Color0 = texture2D(uTextureUnit0, vTextureCoord0);
+
+       if (bool(uTextureUsage1))
+               Color1 = texture2D(uTextureUnit1, vTextureCoord1);
+
+       vec4 FinalColor = (Color0 * Color1) * vVertexColor + vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               FinalColor = mix(FogColor, FinalColor, FogFactor);
+       }
+
+       gl_FragColor = FinalColor;
+}
diff --git a/media/Shaders/Reflection2Layer.vsh b/media/Shaders/Reflection2Layer.vsh
new file mode 100644 (file)
index 0000000..aafac22
--- /dev/null
@@ -0,0 +1,55 @@
+#version 100
+
+/* Attributes */
+
+attribute vec3 inVertexPosition;
+attribute vec3 inVertexNormal;
+attribute vec4 inVertexColor;
+attribute vec2 inTexCoord0;
+attribute vec2 inTexCoord1;
+
+/* Uniforms */
+
+uniform mat4 uWVPMatrix;
+uniform mat4 uWVMatrix;
+uniform mat4 uNMatrix;
+uniform mat4 uTMatrix0;
+
+uniform vec4 uGlobalAmbient;
+uniform vec4 uMaterialAmbient;
+uniform vec4 uMaterialDiffuse;
+uniform vec4 uMaterialEmissive;
+uniform vec4 uMaterialSpecular;
+uniform float uMaterialShininess;
+
+uniform float uThickness;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec2 vTextureCoord1;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+void main()
+{
+       gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0);
+       gl_PointSize = uThickness;
+
+       vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0);
+       vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy;
+
+       vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz;
+       vec3 P = normalize(Position);
+       vec3 N = normalize(vec4(uNMatrix * vec4(inVertexNormal, 0.0)).xyz);
+       vec3 R = reflect(P, N);
+
+       float V = 2.0 * sqrt(R.x*R.x + R.y*R.y + (R.z+1.0)*(R.z+1.0));
+       vTextureCoord1 = vec2(R.x/V + 0.5, R.y/V + 0.5);
+
+       vVertexColor = inVertexColor.bgra;
+       vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0);
+
+       vFogCoord = length(Position);
+}
diff --git a/media/Shaders/Renderer2D.fsh b/media/Shaders/Renderer2D.fsh
new file mode 100644 (file)
index 0000000..89aef7e
--- /dev/null
@@ -0,0 +1,23 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage;
+uniform sampler2D uTextureUnit;
+
+/* Varyings */
+
+varying vec2 vTextureCoord;
+varying vec4 vVertexColor;
+
+void main()
+{
+       vec4 Color = vVertexColor;
+
+       if (bool(uTextureUsage))
+               Color *= texture2D(uTextureUnit, vTextureCoord);
+
+       gl_FragColor = Color;
+}
diff --git a/media/Shaders/Renderer2D.vsh b/media/Shaders/Renderer2D.vsh
new file mode 100644 (file)
index 0000000..9142148
--- /dev/null
@@ -0,0 +1,24 @@
+#version 100
+
+/* Attributes */
+
+attribute vec4 inVertexPosition;
+attribute vec4 inVertexColor;
+attribute vec2 inTexCoord0;
+
+/* Uniforms */
+
+uniform float uThickness;
+
+/* Varyings */
+
+varying vec2 vTextureCoord;
+varying vec4 vVertexColor;
+
+void main()
+{
+       gl_Position = inVertexPosition;
+       gl_PointSize = uThickness;
+       vTextureCoord = inTexCoord0;
+       vVertexColor = inVertexColor.bgra;
+}
diff --git a/media/Shaders/Renderer2D_noTex.fsh b/media/Shaders/Renderer2D_noTex.fsh
new file mode 100644 (file)
index 0000000..6000972
--- /dev/null
@@ -0,0 +1,11 @@
+#version 100
+
+precision mediump float;
+
+/* Varyings */
+varying vec4 vVertexColor;
+
+void main()
+{
+       gl_FragColor = vVertexColor;
+}
diff --git a/media/Shaders/Solid.fsh b/media/Shaders/Solid.fsh
new file mode 100644 (file)
index 0000000..df1010e
--- /dev/null
@@ -0,0 +1,64 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage0;
+uniform sampler2D uTextureUnit0;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color = vVertexColor;
+
+       if (bool(uTextureUsage0))
+               Color *= texture2D(uTextureUnit0, vTextureCoord0);
+       Color += vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               Color = mix(FogColor, Color, FogFactor);
+       }
+
+       gl_FragColor = Color;
+}
diff --git a/media/Shaders/Solid.vsh b/media/Shaders/Solid.vsh
new file mode 100644 (file)
index 0000000..98d0dae
--- /dev/null
@@ -0,0 +1,47 @@
+#version 100
+
+/* Attributes */
+
+attribute vec3 inVertexPosition;
+attribute vec3 inVertexNormal;
+attribute vec4 inVertexColor;
+attribute vec2 inTexCoord0;
+
+/* Uniforms */
+
+uniform mat4 uWVPMatrix;
+uniform mat4 uWVMatrix;
+uniform mat4 uNMatrix;
+uniform mat4 uTMatrix0;
+
+uniform vec4 uGlobalAmbient;
+uniform vec4 uMaterialAmbient;
+uniform vec4 uMaterialDiffuse;
+uniform vec4 uMaterialEmissive;
+uniform vec4 uMaterialSpecular;
+uniform float uMaterialShininess;
+
+uniform float uThickness;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+void main()
+{
+       gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0);
+       gl_PointSize = uThickness;
+
+       vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0);
+       vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy;
+
+       vVertexColor = inVertexColor.bgra;
+       vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0);
+
+       vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz;
+
+       vFogCoord = length(Position);
+}
diff --git a/media/Shaders/Solid2.vsh b/media/Shaders/Solid2.vsh
new file mode 100644 (file)
index 0000000..c49ecfc
--- /dev/null
@@ -0,0 +1,53 @@
+#version 100
+
+/* Attributes */
+
+attribute vec3 inVertexPosition;
+attribute vec3 inVertexNormal;
+attribute vec4 inVertexColor;
+attribute vec2 inTexCoord0;
+attribute vec2 inTexCoord1;
+
+/* Uniforms */
+
+uniform mat4 uWVPMatrix;
+uniform mat4 uWVMatrix;
+uniform mat4 uNMatrix;
+uniform mat4 uTMatrix0;
+uniform mat4 uTMatrix1;
+
+uniform vec4 uGlobalAmbient;
+uniform vec4 uMaterialAmbient;
+uniform vec4 uMaterialDiffuse;
+uniform vec4 uMaterialEmissive;
+uniform vec4 uMaterialSpecular;
+uniform float uMaterialShininess;
+
+uniform float uThickness;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec2 vTextureCoord1;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+void main()
+{
+       gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0);
+       gl_PointSize = uThickness;
+
+       vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0);
+       vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy;
+
+       vec4 TextureCoord1 = vec4(inTexCoord1.x, inTexCoord1.y, 1.0, 1.0);
+       vTextureCoord1 = vec4(uTMatrix1 * TextureCoord1).xy;
+
+       vVertexColor = inVertexColor.bgra;
+       vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0);
+
+       vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz;
+
+       vFogCoord = length(Position);
+}
diff --git a/media/Shaders/Solid2Layer.fsh b/media/Shaders/Solid2Layer.fsh
new file mode 100644 (file)
index 0000000..3c8a39d
--- /dev/null
@@ -0,0 +1,74 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage0;
+uniform int uTextureUsage1;
+uniform sampler2D uTextureUnit0;
+uniform sampler2D uTextureUnit1;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec2 vTextureCoord1;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color0 = vec4(1.0, 1.0, 1.0, 1.0);
+       vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
+
+       if (bool(uTextureUsage0))
+               Color0 = texture2D(uTextureUnit0, vTextureCoord0);
+
+       if (bool(uTextureUsage1))
+               Color1 = texture2D(uTextureUnit1, vTextureCoord1);
+
+       vec4 FinalColor = (Color0 * vVertexColor.a + Color1 * (1.0 - vVertexColor.a)) * vVertexColor;
+       FinalColor += vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               FinalColor = mix(FogColor, FinalColor, FogFactor);
+       }
+
+       gl_FragColor = FinalColor;
+
+}
diff --git a/media/Shaders/SphereMap.fsh b/media/Shaders/SphereMap.fsh
new file mode 100644 (file)
index 0000000..df1010e
--- /dev/null
@@ -0,0 +1,64 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage0;
+uniform sampler2D uTextureUnit0;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color = vVertexColor;
+
+       if (bool(uTextureUsage0))
+               Color *= texture2D(uTextureUnit0, vTextureCoord0);
+       Color += vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               Color = mix(FogColor, Color, FogFactor);
+       }
+
+       gl_FragColor = Color;
+}
diff --git a/media/Shaders/SphereMap.vsh b/media/Shaders/SphereMap.vsh
new file mode 100644 (file)
index 0000000..5062d79
--- /dev/null
@@ -0,0 +1,50 @@
+#version 100
+
+/* Attributes */
+
+attribute vec3 inVertexPosition;
+attribute vec3 inVertexNormal;
+attribute vec4 inVertexColor;
+attribute vec2 inTexCoord0;
+attribute vec2 inTexCoord1;
+
+/* Uniforms */
+
+uniform mat4 uWVPMatrix;
+uniform mat4 uWVMatrix;
+uniform mat4 uNMatrix;
+
+uniform vec4 uGlobalAmbient;
+uniform vec4 uMaterialAmbient;
+uniform vec4 uMaterialDiffuse;
+uniform vec4 uMaterialEmissive;
+uniform vec4 uMaterialSpecular;
+uniform float uMaterialShininess;
+
+uniform float uThickness;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+void main()
+{
+       gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0);
+       gl_PointSize = uThickness;
+
+       vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz;
+       vec3 P = normalize(Position);
+       vec3 N = normalize(vec4(uNMatrix * vec4(inVertexNormal, 0.0)).xyz);
+       vec3 R = reflect(P, N);
+
+       float V = 2.0 * sqrt(R.x*R.x + R.y*R.y + (R.z+1.0)*(R.z+1.0));
+       vTextureCoord0 = vec2(R.x/V + 0.5, R.y/V + 0.5);
+
+       vVertexColor = inVertexColor.bgra;
+       vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0);
+
+       vFogCoord = length(Position);
+}
diff --git a/media/Shaders/TransparentAlphaChannel.fsh b/media/Shaders/TransparentAlphaChannel.fsh
new file mode 100644 (file)
index 0000000..cef349a
--- /dev/null
@@ -0,0 +1,71 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform float uAlphaRef;
+uniform int uTextureUsage0;
+uniform sampler2D uTextureUnit0;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color = vVertexColor;
+
+       if (bool(uTextureUsage0))
+       {
+               Color *= texture2D(uTextureUnit0, vTextureCoord0);
+
+               // TODO: uAlphaRef should rather control sharpness of alpha, don't know how to do that right now and this works in most cases.
+               if (Color.a < uAlphaRef)
+                       discard;
+       }
+       Color += vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               Color = mix(FogColor, Color, FogFactor);
+       }
+
+       gl_FragColor = Color;
+}
diff --git a/media/Shaders/TransparentAlphaChannelRef.fsh b/media/Shaders/TransparentAlphaChannelRef.fsh
new file mode 100644 (file)
index 0000000..fab4eee
--- /dev/null
@@ -0,0 +1,69 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform float uAlphaRef;
+uniform int uTextureUsage0;
+uniform sampler2D uTextureUnit0;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color = vVertexColor;
+
+       if (bool(uTextureUsage0))
+               Color *= texture2D(uTextureUnit0, vTextureCoord0);
+
+       if (Color.a < uAlphaRef)
+               discard;
+
+       Color += vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               Color = mix(FogColor, Color, FogFactor);
+       }
+
+       gl_FragColor = Color;
+}
diff --git a/media/Shaders/TransparentVertexAlpha.fsh b/media/Shaders/TransparentVertexAlpha.fsh
new file mode 100644 (file)
index 0000000..df1010e
--- /dev/null
@@ -0,0 +1,64 @@
+#version 100
+
+precision mediump float;
+
+/* Uniforms */
+
+uniform int uTextureUsage0;
+uniform sampler2D uTextureUnit0;
+uniform int uFogEnable;
+uniform int uFogType;
+uniform vec4 uFogColor;
+uniform float uFogStart;
+uniform float uFogEnd;
+uniform float uFogDensity;
+
+/* Varyings */
+
+varying vec2 vTextureCoord0;
+varying vec4 vVertexColor;
+varying vec4 vSpecularColor;
+varying float vFogCoord;
+
+float computeFog()
+{
+       const float LOG2 = 1.442695;
+       float FogFactor = 0.0;
+
+       if (uFogType == 0) // Exp
+       {
+               FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
+       }
+       else if (uFogType == 1) // Linear
+       {
+               float Scale = 1.0 / (uFogEnd - uFogStart);
+               FogFactor = (uFogEnd - vFogCoord) * Scale;
+       }
+       else if (uFogType == 2) // Exp2
+       {
+               FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
+       }
+
+       FogFactor = clamp(FogFactor, 0.0, 1.0);
+
+       return FogFactor;
+}
+
+void main()
+{
+       vec4 Color = vVertexColor;
+
+       if (bool(uTextureUsage0))
+               Color *= texture2D(uTextureUnit0, vTextureCoord0);
+       Color += vSpecularColor;
+
+       if (bool(uFogEnable))
+       {
+               float FogFactor = computeFog();
+               vec4 FogColor = uFogColor;
+               FogColor.a = 1.0;
+               Color = mix(FogColor, Color, FogFactor);
+       }
+
+       gl_FragColor = Color;
+}