OpenGL2: Fix applying tcMod turb

Shader stage tcMods for matrix and turb effects need to be applied in
order for turb to be correct and all tcMod turb need to be applied
instead of only the last one.

Quake 3's textures/liquids/slime1 had tcMod turb and then tcMod scale.
OpenGL2 applied the matrix first and then turb which had the wrong result.
This commit is contained in:
Zack Middleton committed 2024-01-18 03:16:39 -05:00
1 parent 5ede35d8dd
commit 93abc60a5b
6 files changed
+190 -77

No files matched your search

+40 -14
View File
@@ -16,8 +16,16 @@ attribute vec4 attr_TexCoord0;
attribute vec4 attr_TexCoord1;
#endif
uniform vec4 u_DiffuseTexMatrix;
uniform vec4 u_DiffuseTexOffTurb;
#if defined(USE_TCMOD)
uniform vec4 u_DiffuseTexMatrix0;
uniform vec4 u_DiffuseTexMatrix1;
uniform vec4 u_DiffuseTexMatrix2;
uniform vec4 u_DiffuseTexMatrix3;
uniform vec4 u_DiffuseTexMatrix4;
uniform vec4 u_DiffuseTexMatrix5;
uniform vec4 u_DiffuseTexMatrix6;
uniform vec4 u_DiffuseTexMatrix7;
#endif
#if defined(USE_TCGEN) || defined(USE_RGBAGEN)
uniform vec3 u_LocalViewOrigin;
@@ -140,19 +148,28 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
#endif
#if defined(USE_TCMOD)
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix[8])
{
float amplitude = offTurb.z;
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);
vec2 st2 = st;
vec2 offsetPos = vec2(position.x + position.z, position.y);
vec2 texOffset = sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(phase));
return st2 + texOffset * amplitude;
st2 = vec2(st2.x * texMatrix[0].x + st2.y * texMatrix[0].y + texMatrix[0].z,
st2.x * texMatrix[1].x + st2.y * texMatrix[1].y + texMatrix[1].z);
st2 += texMatrix[0].w * sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(texMatrix[1].w * 2.0 * M_PI));
st2 = vec2(st2.x * texMatrix[2].x + st2.y * texMatrix[2].y + texMatrix[2].z,
st2.x * texMatrix[3].x + st2.y * texMatrix[3].y + texMatrix[3].z);
st2 += texMatrix[2].w * sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(texMatrix[3].w * 2.0 * M_PI));
st2 = vec2(st2.x * texMatrix[4].x + st2.y * texMatrix[4].y + texMatrix[4].z,
st2.x * texMatrix[5].x + st2.y * texMatrix[5].y + texMatrix[5].z);
st2 += texMatrix[4].w * sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(texMatrix[5].w * 2.0 * M_PI));
st2 = vec2(st2.x * texMatrix[6].x + st2.y * texMatrix[6].y + texMatrix[6].z,
st2.x * texMatrix[7].x + st2.y * texMatrix[7].y + texMatrix[7].z);
st2 += texMatrix[6].w * sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(texMatrix[7].w * 2.0 * M_PI));
return st2;
}
#endif
@@ -236,7 +253,16 @@ void main()
#endif
#if defined(USE_TCMOD)
var_DiffuseTex = ModTexCoords(tex, position, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
vec4 diffuseTexMatrix[8];
diffuseTexMatrix[0] = u_DiffuseTexMatrix0;
diffuseTexMatrix[1] = u_DiffuseTexMatrix1;
diffuseTexMatrix[2] = u_DiffuseTexMatrix2;
diffuseTexMatrix[3] = u_DiffuseTexMatrix3;
diffuseTexMatrix[4] = u_DiffuseTexMatrix4;
diffuseTexMatrix[5] = u_DiffuseTexMatrix5;
diffuseTexMatrix[6] = u_DiffuseTexMatrix6;
diffuseTexMatrix[7] = u_DiffuseTexMatrix7;
var_DiffuseTex = ModTexCoords(tex, position, diffuseTexMatrix);
#else
var_DiffuseTex = tex;
#endif
+36 -12
View File
@@ -37,8 +37,14 @@ uniform vec3 u_LocalViewOrigin;
#endif
#if defined(USE_TCMOD)
uniform vec4 u_DiffuseTexMatrix;
uniform vec4 u_DiffuseTexOffTurb;
uniform vec4 u_DiffuseTexMatrix0;
uniform vec4 u_DiffuseTexMatrix1;
uniform vec4 u_DiffuseTexMatrix2;
uniform vec4 u_DiffuseTexMatrix3;
uniform vec4 u_DiffuseTexMatrix4;
uniform vec4 u_DiffuseTexMatrix5;
uniform vec4 u_DiffuseTexMatrix6;
uniform vec4 u_DiffuseTexMatrix7;
#endif
uniform mat4 u_ModelViewProjectionMatrix;
@@ -114,19 +120,28 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
#endif
#if defined(USE_TCMOD)
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix[8])
{
float amplitude = offTurb.z;
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);
vec2 st2 = st;
vec2 offsetPos = vec2(position.x + position.z, position.y);
vec2 texOffset = sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(phase));
st2 = vec2(st2.x * texMatrix[0].x + st2.y * texMatrix[0].y + texMatrix[0].z,
st2.x * texMatrix[1].x + st2.y * texMatrix[1].y + texMatrix[1].z);
st2 += texMatrix[0].w * sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(texMatrix[1].w * 2.0 * M_PI));
return st2 + texOffset * amplitude;
st2 = vec2(st2.x * texMatrix[2].x + st2.y * texMatrix[2].y + texMatrix[2].z,
st2.x * texMatrix[3].x + st2.y * texMatrix[3].y + texMatrix[3].z);
st2 += texMatrix[2].w * sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(texMatrix[3].w * 2.0 * M_PI));
st2 = vec2(st2.x * texMatrix[4].x + st2.y * texMatrix[4].y + texMatrix[4].z,
st2.x * texMatrix[5].x + st2.y * texMatrix[5].y + texMatrix[5].z);
st2 += texMatrix[4].w * sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(texMatrix[5].w * 2.0 * M_PI));
st2 = vec2(st2.x * texMatrix[6].x + st2.y * texMatrix[6].y + texMatrix[6].z,
st2.x * texMatrix[7].x + st2.y * texMatrix[7].y + texMatrix[7].z);
st2 += texMatrix[6].w * sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(texMatrix[7].w * 2.0 * M_PI));
return st2;
}
#endif
@@ -183,7 +198,16 @@ void main()
#endif
#if defined(USE_TCMOD)
var_TexCoords.xy = ModTexCoords(texCoords, position, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
vec4 diffuseTexMatrix[8];
diffuseTexMatrix[0] = u_DiffuseTexMatrix0;
diffuseTexMatrix[1] = u_DiffuseTexMatrix1;
diffuseTexMatrix[2] = u_DiffuseTexMatrix2;
diffuseTexMatrix[3] = u_DiffuseTexMatrix3;
diffuseTexMatrix[4] = u_DiffuseTexMatrix4;
diffuseTexMatrix[5] = u_DiffuseTexMatrix5;
diffuseTexMatrix[6] = u_DiffuseTexMatrix6;
diffuseTexMatrix[7] = u_DiffuseTexMatrix7;
var_TexCoords.xy = ModTexCoords(texCoords, position, diffuseTexMatrix);
#else
var_TexCoords.xy = texCoords;
#endif