Add CopyToArray method for IPalette.

By allowing a palette to be copied to an array, a speedup can be gained in HardwarePalette since palettes can be block copied using native magic rather than having to copy them item by item. We transpose the buffer in HardwarePalette in order to allow a contiguous block copy into this buffer, transposing again in the shader to keep everything correct.
This commit is contained in:
RoosterDragon
2014-12-07 20:46:46 +00:00
parent 51f874fae2
commit 8c2fdb9097
4 changed files with 33 additions and 13 deletions

View File

@@ -3,6 +3,6 @@ uniform sampler2D DiffuseTexture, Palette;
void main()
{
vec4 x = texture2D(DiffuseTexture, gl_TexCoord[0].st);
vec2 p = vec2(gl_TexCoord[0].p, dot(x, gl_TexCoord[1]));
vec2 p = vec2(dot(x, gl_TexCoord[1]), gl_TexCoord[0].p);
gl_FragColor = texture2D(Palette, p);
}

View File

@@ -7,11 +7,11 @@ uniform vec3 AmbientLight, DiffuseLight;
void main()
{
vec4 x = texture2D(DiffuseTexture, gl_TexCoord[0].st);
vec4 color = texture2D(Palette, vec2(PaletteRows.x, dot(x, gl_TexCoord[1])));
vec4 color = texture2D(Palette, vec2(dot(x, gl_TexCoord[1]), PaletteRows.x));
if (color.a < 0.01)
discard;
vec4 normal = (2.0 * texture2D(Palette, vec2(PaletteRows.y, dot(x, gl_TexCoord[2]))) - 1.0);
vec4 normal = (2.0 * texture2D(Palette, vec2(dot(x, gl_TexCoord[2]), PaletteRows.y)) - 1.0);
vec3 intensity = AmbientLight + DiffuseLight * max(dot(normal, LightDirection), 0.0);
gl_FragColor = vec4(intensity * color.rgb, color.a);
}