OpenGL2: Small glsl shader optimizations, fixes, and cleanup.

This commit is contained in:
SmileTheory 2013-12-12 21:38:01 -08:00
parent efe8437cde
commit 623d107f42
15 changed files with 255 additions and 244 deletions

View file

@ -89,11 +89,11 @@ 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(fract(0.5 - value));
}
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
{
func = 1.0 - abs(4.0 * fract(value + 0.25) - 2.0);
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
}
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
{
@ -103,7 +103,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);
}
@ -124,7 +124,9 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
{
vec3 viewer = normalize(u_LocalViewOrigin - position);
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
vec2 ref = reflect(viewer, normal).yz;
tex.s = ref.x * -0.5 + 0.5;
tex.t = ref.y * 0.5 + 0.5;
}
else if (TCGen == TCGEN_VECTOR)
{
@ -139,13 +141,14 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
{
float amplitude = offTurb.z;
float phase = offTurb.w;
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
float phase = offTurb.w * 2.0 * M_PI;
vec2 st2;
st2.x = st.x * texMatrix.x + (st.y * texMatrix.z + offTurb.x);
st2.y = st.x * texMatrix.y + (st.y * texMatrix.w + offTurb.y);
vec3 offsetPos = position / 1024.0;
offsetPos.x += offsetPos.z;
vec2 offsetPos = vec2(position.x + position.z, position.y);
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
vec2 texOffset = sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(phase));
return st2 + texOffset * amplitude;
}
@ -186,13 +189,13 @@ vec4 CalcColor(vec3 position, vec3 normal)
#if defined(USE_FOG)
float CalcFog(vec3 position)
{
float s = (dot(position, u_FogDistance.xyz) + u_FogDistance.w) * 8.0;
float t = dot(position, u_FogDepth.xyz) + u_FogDepth.w;
float s = dot(vec4(position, 1.0), u_FogDistance) * 8.0;
float t = dot(vec4(position, 1.0), u_FogDepth);
float eyeOutside = step(0.0, -u_FogEyeT);
float fogged = step(eyeOutside, t);
t = max(t, 1e-6);
float eyeOutside = float(u_FogEyeT < 0.0);
float fogged = float(t < eyeOutside);
t += 1e-6;
t *= fogged / (t - u_FogEyeT * eyeOutside);
return s * t;
@ -202,8 +205,9 @@ float CalcFog(vec3 position)
void main()
{
#if defined(USE_VERTEX_ANIMATION)
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp) * 2.0 - vec3(1.0));
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
vec3 position = attr_Position;
vec3 normal = attr_Normal * 2.0 - vec3(1.0);