summaryrefslogtreecommitdiff
path: root/src/renderergl2/glsl/fogpass_vp.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderergl2/glsl/fogpass_vp.glsl')
-rw-r--r--src/renderergl2/glsl/fogpass_vp.glsl50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/renderergl2/glsl/fogpass_vp.glsl b/src/renderergl2/glsl/fogpass_vp.glsl
index a07a5fdd..8f7bc728 100644
--- a/src/renderergl2/glsl/fogpass_vp.glsl
+++ b/src/renderergl2/glsl/fogpass_vp.glsl
@@ -1,27 +1,30 @@
-attribute vec4 attr_Position;
+attribute vec3 attr_Position;
attribute vec3 attr_Normal;
+
attribute vec4 attr_TexCoord0;
-//#if defined(USE_VERTEX_ANIMATION)
-attribute vec4 attr_Position2;
+#if defined(USE_VERTEX_ANIMATION)
+attribute vec3 attr_Position2;
attribute vec3 attr_Normal2;
-//#endif
+#endif
uniform vec4 u_FogDistance;
uniform vec4 u_FogDepth;
uniform float u_FogEyeT;
-//#if defined(USE_DEFORM_VERTEXES)
+#if defined(USE_DEFORM_VERTEXES)
uniform int u_DeformGen;
uniform float u_DeformParams[5];
-//#endif
+#endif
uniform float u_Time;
uniform mat4 u_ModelViewProjectionMatrix;
-//#if defined(USE_VERTEX_ANIMATION)
+#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
-//#endif
+#endif
+
+uniform vec4 u_Color;
varying float var_Scale;
@@ -57,7 +60,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
}
else if (u_DeformGen == DGEN_WAVE_SQUARE)
{
- func = sign(sin(value * 2.0 * M_PI));
+ func = sign(0.5 - fract(value));
}
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
{
@@ -71,7 +74,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
{
func = (1.0 - fract(value));
}
- else if (u_DeformGen == DGEN_BULGE)
+ else // if (u_DeformGen == DGEN_BULGE)
{
func = sin(value);
}
@@ -80,15 +83,15 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
}
#endif
-float CalcFog(vec4 position)
+float CalcFog(vec3 position)
{
- float s = dot(position, u_FogDistance) * 8.0;
- float t = dot(position, u_FogDepth);
+ float s = dot(vec4(position, 1.0), u_FogDistance) * 8.0;
+ float t = dot(vec4(position, 1.0), u_FogDepth);
+
+ float eyeOutside = float(u_FogEyeT < 0.0);
+ float fogged = float(t >= eyeOutside);
- float eyeOutside = step(0.0, -u_FogEyeT);
- float fogged = step(eyeOutside, t);
-
- t = max(t, 1e-6);
+ t += 1e-6;
t *= fogged / (t - u_FogEyeT * eyeOutside);
return s * t;
@@ -97,18 +100,19 @@ float CalcFog(vec4 position)
void main()
{
#if defined(USE_VERTEX_ANIMATION)
- vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
- vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
+ vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
+ vec3 normal = mix(attr_Normal, attr_Normal2, u_VertexLerp);
+ normal = normalize(normal - vec3(0.5));
#else
- vec4 position = attr_Position;
- vec3 normal = attr_Normal;
+ vec3 position = attr_Position;
+ vec3 normal = attr_Normal * 2.0 - vec3(1.0);
#endif
#if defined(USE_DEFORM_VERTEXES)
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
#endif
- gl_Position = u_ModelViewProjectionMatrix * position;
+ gl_Position = u_ModelViewProjectionMatrix * vec4(position, 1.0);
- var_Scale = CalcFog(position);
+ var_Scale = CalcFog(position) * u_Color.a * u_Color.a;
}