Use varyings for masks instead of overloading gl_TexCoord.
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
uniform sampler2D DiffuseTexture, Palette;
|
uniform sampler2D DiffuseTexture, Palette;
|
||||||
|
|
||||||
|
varying vec4 TexCoord;
|
||||||
|
varying vec4 ChannelMask;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 x = texture2D(DiffuseTexture, gl_TexCoord[0].st);
|
vec4 x = texture2D(DiffuseTexture, TexCoord.st);
|
||||||
vec2 p = vec2(dot(x, gl_TexCoord[1]), gl_TexCoord[0].p);
|
vec2 p = vec2(dot(x, ChannelMask), TexCoord.p);
|
||||||
gl_FragColor = texture2D(Palette, p);
|
gl_FragColor = texture2D(Palette, p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
uniform vec2 Scroll;
|
uniform vec2 Scroll;
|
||||||
uniform vec2 r1,r2; // matrix elements
|
uniform vec2 r1,r2; // matrix elements
|
||||||
|
|
||||||
|
varying vec4 TexCoord;
|
||||||
|
varying vec4 ChannelMask;
|
||||||
|
|
||||||
vec4 DecodeChannelMask( float x )
|
vec4 DecodeChannelMask( float x )
|
||||||
{
|
{
|
||||||
if (x > 0.0)
|
if (x > 0.0)
|
||||||
@@ -13,6 +16,6 @@ void main()
|
|||||||
{
|
{
|
||||||
vec2 p = (gl_Vertex.xy - Scroll.xy)*r1 + r2;
|
vec2 p = (gl_Vertex.xy - Scroll.xy)*r1 + r2;
|
||||||
gl_Position = vec4(p.x,p.y,0,1);
|
gl_Position = vec4(p.x,p.y,0,1);
|
||||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
TexCoord = gl_MultiTexCoord0;
|
||||||
gl_TexCoord[1] = DecodeChannelMask(gl_MultiTexCoord0.w);
|
ChannelMask = DecodeChannelMask(gl_MultiTexCoord0.w);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,18 @@ uniform vec2 PaletteRows;
|
|||||||
uniform vec4 LightDirection;
|
uniform vec4 LightDirection;
|
||||||
uniform vec3 AmbientLight, DiffuseLight;
|
uniform vec3 AmbientLight, DiffuseLight;
|
||||||
|
|
||||||
|
varying vec4 TexCoord;
|
||||||
|
varying vec4 ChannelMask;
|
||||||
|
varying vec4 NormalsMask;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 x = texture2D(DiffuseTexture, gl_TexCoord[0].st);
|
vec4 x = texture2D(DiffuseTexture, TexCoord.st);
|
||||||
vec4 color = texture2D(Palette, vec2(dot(x, gl_TexCoord[1]), PaletteRows.x));
|
vec4 color = texture2D(Palette, vec2(dot(x, ChannelMask), PaletteRows.x));
|
||||||
if (color.a < 0.01)
|
if (color.a < 0.01)
|
||||||
discard;
|
discard;
|
||||||
|
|
||||||
vec4 normal = (2.0 * texture2D(Palette, vec2(dot(x, gl_TexCoord[2]), PaletteRows.y)) - 1.0);
|
vec4 normal = (2.0 * texture2D(Palette, vec2(dot(x, NormalsMask), PaletteRows.y)) - 1.0);
|
||||||
vec3 intensity = AmbientLight + DiffuseLight * max(dot(normal, LightDirection), 0.0);
|
vec3 intensity = AmbientLight + DiffuseLight * max(dot(normal, LightDirection), 0.0);
|
||||||
gl_FragColor = vec4(intensity * color.rgb, color.a);
|
gl_FragColor = vec4(intensity * color.rgb, color.a);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
uniform mat4 View;
|
uniform mat4 View;
|
||||||
uniform mat4 TransformMatrix;
|
uniform mat4 TransformMatrix;
|
||||||
|
|
||||||
vec4 DecodeChannelMask(float x)
|
varying vec4 TexCoord;
|
||||||
|
varying vec4 ChannelMask;
|
||||||
|
varying vec4 NormalsMask;
|
||||||
|
|
||||||
|
vec4 DecodeMask(float x)
|
||||||
{
|
{
|
||||||
if (x > 0.0)
|
if (x > 0.0)
|
||||||
return (x > 0.5) ? vec4(1,0,0,0) : vec4(0,1,0,0);
|
return (x > 0.5) ? vec4(1,0,0,0) : vec4(0,1,0,0);
|
||||||
@@ -12,7 +16,7 @@ vec4 DecodeChannelMask(float x)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = View*TransformMatrix*gl_Vertex;
|
gl_Position = View*TransformMatrix*gl_Vertex;
|
||||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
TexCoord = gl_MultiTexCoord0;
|
||||||
gl_TexCoord[1] = DecodeChannelMask(gl_MultiTexCoord0.z);
|
ChannelMask = DecodeMask(gl_MultiTexCoord0.z);
|
||||||
gl_TexCoord[2] = DecodeChannelMask(gl_MultiTexCoord0.w);
|
NormalsMask = DecodeMask(gl_MultiTexCoord0.w);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user