Improve batching by binding up to 8 simultaneous textures.
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
uniform sampler2D DiffuseTexture, Palette;
|
||||
uniform sampler2D Texture0;
|
||||
uniform sampler2D Texture1;
|
||||
uniform sampler2D Texture2;
|
||||
uniform sampler2D Texture3;
|
||||
uniform sampler2D Texture4;
|
||||
uniform sampler2D Texture5;
|
||||
uniform sampler2D Texture6;
|
||||
uniform sampler2D Texture7;
|
||||
uniform sampler2D Palette;
|
||||
|
||||
uniform bool EnableDepthPreview;
|
||||
uniform float DepthTextureScale;
|
||||
@@ -7,6 +15,7 @@ varying vec4 vTexCoord;
|
||||
varying vec2 vTexMetadata;
|
||||
varying vec4 vChannelMask;
|
||||
varying vec4 vDepthMask;
|
||||
varying vec2 vTexSampler;
|
||||
|
||||
varying vec4 vColorFraction;
|
||||
varying vec4 vRGBAFraction;
|
||||
@@ -27,9 +36,29 @@ float jet_b(float x)
|
||||
return x < 0.3 ? 4.0 * x + 0.5 : -4.0 * x + 2.5;
|
||||
}
|
||||
|
||||
vec4 Sample(float samplerIndex, vec2 pos)
|
||||
{
|
||||
if (samplerIndex < 1.0)
|
||||
return texture2D(Texture0, pos);
|
||||
else if (samplerIndex < 2.0)
|
||||
return texture2D(Texture1, pos);
|
||||
else if (samplerIndex < 3.0)
|
||||
return texture2D(Texture2, pos);
|
||||
else if (samplerIndex < 4.0)
|
||||
return texture2D(Texture3, pos);
|
||||
else if (samplerIndex < 5.0)
|
||||
return texture2D(Texture4, pos);
|
||||
else if (samplerIndex < 6.0)
|
||||
return texture2D(Texture5, pos);
|
||||
else if (samplerIndex < 7.0)
|
||||
return texture2D(Texture6, pos);
|
||||
|
||||
return texture2D(Texture7, pos);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 x = texture2D(DiffuseTexture, vTexCoord.st);
|
||||
vec4 x = Sample(vTexSampler.s, vTexCoord.st);
|
||||
vec2 p = vec2(dot(x, vChannelMask), vTexMetadata.s);
|
||||
vec4 c = vPalettedFraction * texture2D(Palette, p) + vRGBAFraction * x + vColorFraction * vTexCoord;
|
||||
|
||||
@@ -40,7 +69,7 @@ void main()
|
||||
float depth = gl_FragCoord.z;
|
||||
if (length(vDepthMask) > 0.0)
|
||||
{
|
||||
vec4 y = texture2D(DiffuseTexture, vTexCoord.pq);
|
||||
vec4 y = Sample(vTexSampler.t, vTexCoord.pq);
|
||||
depth = depth + DepthTextureScale * dot(y, vDepthMask);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,15 +9,18 @@ varying vec4 vTexCoord;
|
||||
varying vec2 vTexMetadata;
|
||||
varying vec4 vChannelMask;
|
||||
varying vec4 vDepthMask;
|
||||
varying vec2 vTexSampler;
|
||||
|
||||
varying vec4 vColorFraction;
|
||||
varying vec4 vRGBAFraction;
|
||||
varying vec4 vPalettedFraction;
|
||||
|
||||
vec2 UnpackChannelAttributes(float x)
|
||||
vec4 UnpackChannelAttributes(float x)
|
||||
{
|
||||
// The channel attributes float encodes a set of attributes
|
||||
// stored as flags in the mantissa of the unnormalized float value.
|
||||
// Bits 9-11 define the sampler index (0-7) that the secondary texture is bound to
|
||||
// Bits 6-8 define the sampler index (0-7) that the primary texture is bound to
|
||||
// Bits 3-5 define the behaviour of the secondary texture channel:
|
||||
// 000: Channel is not used
|
||||
// 001, 011, 101, 111: Sample depth sprite from channel R,G,B,A
|
||||
@@ -26,6 +29,16 @@ vec2 UnpackChannelAttributes(float x)
|
||||
// 010: Sample RGBA sprite from all four channels
|
||||
// 001, 011, 101, 111: Sample paletted sprite from channel R,G,B,A
|
||||
|
||||
float secondarySampler = 0.0;
|
||||
if (x >= 2048.0) { x -= 2048.0; secondarySampler += 4.0; }
|
||||
if (x >= 1024.0) { x -= 1024.0; secondarySampler += 2.0; }
|
||||
if (x >= 512.0) { x -= 512.0; secondarySampler += 1.0; }
|
||||
|
||||
float primarySampler = 0.0;
|
||||
if (x >= 256.0) { x -= 256.0; primarySampler += 4.0; }
|
||||
if (x >= 128.0) { x -= 128.0; primarySampler += 2.0; }
|
||||
if (x >= 64.0) { x -= 64.0; primarySampler += 1.0; }
|
||||
|
||||
float secondaryChannel = 0.0;
|
||||
if (x >= 32.0) { x -= 32.0; secondaryChannel += 4.0; }
|
||||
if (x >= 16.0) { x -= 16.0; secondaryChannel += 2.0; }
|
||||
@@ -36,7 +49,7 @@ vec2 UnpackChannelAttributes(float x)
|
||||
if (x >= 2.0) { x -= 2.0; primaryChannel += 2.0; }
|
||||
if (x >= 1.0) { x -= 1.0; primaryChannel += 1.0; }
|
||||
|
||||
return vec2(primaryChannel, secondaryChannel);
|
||||
return vec4(primaryChannel, secondaryChannel, primarySampler, secondarySampler);
|
||||
}
|
||||
|
||||
vec4 SelectChannelMask(float x)
|
||||
@@ -85,10 +98,11 @@ void main()
|
||||
vTexCoord = aVertexTexCoord;
|
||||
vTexMetadata = aVertexTexMetadata;
|
||||
|
||||
vec2 attrib = UnpackChannelAttributes(aVertexTexMetadata.t);
|
||||
vec4 attrib = UnpackChannelAttributes(aVertexTexMetadata.t);
|
||||
vChannelMask = SelectChannelMask(attrib.s);
|
||||
vColorFraction = SelectColorFraction(attrib.s);
|
||||
vRGBAFraction = SelectRGBAFraction(attrib.s);
|
||||
vPalettedFraction = SelectPalettedFraction(attrib.s);
|
||||
vDepthMask = SelectChannelMask(attrib.t);
|
||||
vTexSampler = attrib.pq;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user