Merge RGBA sprite rendering into SpriteRenderer.

Renderer.RgbaSpriteRenderer is kept as a thin
wrapper to maintain compatibility with consumer
code.
This commit is contained in:
Paul Chote
2018-05-31 22:07:40 +00:00
committed by reaperrr
parent ba38878933
commit 131496ebf8
10 changed files with 95 additions and 92 deletions

View File

@@ -1,43 +0,0 @@
uniform sampler2D DiffuseTexture;
uniform bool EnableDepthPreview;
varying vec4 vTexCoord;
float jet_r(float x)
{
return x < 0.7 ? 4.0 * x - 1.5 : -4.0 * x + 4.5;
}
float jet_g(float x)
{
return x < 0.5 ? 4.0 * x - 0.5 : -4.0 * x + 3.5;
}
float jet_b(float x)
{
return x < 0.3 ? 4.0 * x + 0.5 : -4.0 * x + 2.5;
}
void main()
{
vec4 c = texture2D(DiffuseTexture, vTexCoord.st);
// Discard any transparent fragments (both color and depth)
if (c.a == 0.0)
discard;
float depth = gl_FragCoord.z;
// Convert to window coords
gl_FragDepth = 0.5 * depth + 0.5;
if (EnableDepthPreview)
{
float x = 1.0 - gl_FragDepth;
float r = clamp(jet_r(x), 0.0, 1.0);
float g = clamp(jet_g(x), 0.0, 1.0);
float b = clamp(jet_b(x), 0.0, 1.0);
gl_FragColor = vec4(r, g, b, 1.0);
}
else
gl_FragColor = c;
}

View File

@@ -1,12 +0,0 @@
uniform vec3 Scroll;
uniform vec3 r1, r2;
attribute vec4 aVertexPosition;
attribute vec4 aVertexTexCoord;
varying vec4 vTexCoord;
void main()
{
gl_Position = vec4((aVertexPosition.xyz - Scroll.xyz) * r1 + r2, 1);
vTexCoord = aVertexTexCoord;
}

View File

@@ -7,7 +7,10 @@ varying vec4 vTexCoord;
varying vec2 vTexMetadata;
varying vec4 vChannelMask;
varying vec4 vDepthMask;
varying vec4 vColorFraction;
varying vec4 vRGBAFraction;
varying vec4 vPalettedFraction;
float jet_r(float x)
{
@@ -28,7 +31,7 @@ void main()
{
vec4 x = texture2D(DiffuseTexture, vTexCoord.st);
vec2 p = vec2(dot(x, vChannelMask), vTexMetadata.s);
vec4 c = (vec4(1, 1, 1, 1) - vColorFraction) * texture2D(Palette, p) + vColorFraction * vTexCoord;
vec4 c = vPalettedFraction * texture2D(Palette, p) + vRGBAFraction * x + vColorFraction * vTexCoord;
// Discard any transparent fragments (both color and depth)
if (c.a == 0.0)

View File

@@ -4,11 +4,15 @@ uniform vec3 r1, r2;
attribute vec4 aVertexPosition;
attribute vec4 aVertexTexCoord;
attribute vec2 aVertexTexMetadata;
varying vec4 vTexCoord;
varying vec2 vTexMetadata;
varying vec4 vChannelMask;
varying vec4 vDepthMask;
varying vec4 vColorFraction;
varying vec4 vRGBAFraction;
varying vec4 vPalettedFraction;
vec2 UnpackChannelAttributes(float x)
{
@@ -19,6 +23,7 @@ vec2 UnpackChannelAttributes(float x)
// 001, 011, 101, 111: Sample depth sprite from channel R,G,B,A
// Bits 0-2 define the behaviour of the primary texture channel:
// 000: Channel is not used (aVertexTexCoord instead defines a color value)
// 010: Sample RGBA sprite from all four channels
// 001, 011, 101, 111: Sample paletted sprite from channel R,G,B,A
float secondaryChannel = 0.0;
@@ -42,6 +47,8 @@ vec4 SelectChannelMask(float x)
return vec4(0,0,1,0);
if (x >= 3.0)
return vec4(0,1,0,0);
if (x >= 2.0)
return vec4(1,1,1,1);
if (x >= 1.0)
return vec4(1,0,0,0);
@@ -52,8 +59,24 @@ vec4 SelectColorFraction(float x)
{
if (x > 0.0)
return vec4(0, 0, 0, 0);
else
return vec4(1, 1, 1, 1);
}
vec4 SelectRGBAFraction(float x)
{
if (x == 2.0)
return vec4(1, 1, 1, 1);
return vec4(0, 0, 0, 0);
}
vec4 SelectPalettedFraction(float x)
{
if (x == 0.0 || x == 2.0)
return vec4(0, 0, 0, 0);
return vec4(1, 1, 1, 1);
}
void main()
@@ -65,5 +88,7 @@ void main()
vec2 attrib = UnpackChannelAttributes(aVertexTexMetadata.t);
vChannelMask = SelectChannelMask(attrib.s);
vColorFraction = SelectColorFraction(attrib.s);
vRGBAFraction = SelectRGBAFraction(attrib.s);
vPalettedFraction = SelectPalettedFraction(attrib.s);
vDepthMask = SelectChannelMask(attrib.t);
}