mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Cleaned up the GLSL shader files and related code.
This commit is contained in:
parent
7bdce3f4a3
commit
f859fd828d
|
@ -367,12 +367,12 @@ void ImageComponent::updateVertices()
|
|||
|
||||
if (mFlipX) {
|
||||
for (int i = 0; i < 4; ++i)
|
||||
mVertices[i].texture[0] = px - mVertices[i].texture[0];
|
||||
mVertices[i].texcoord[0] = px - mVertices[i].texcoord[0];
|
||||
}
|
||||
|
||||
if (mFlipY) {
|
||||
for (int i = 0; i < 4; ++i)
|
||||
mVertices[i].texture[1] = py - mVertices[i].texture[1];
|
||||
mVertices[i].texcoord[1] = py - mVertices[i].texcoord[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
struct Vertex {
|
||||
glm::vec2 position;
|
||||
glm::vec2 texture;
|
||||
glm::vec2 texcoord;
|
||||
unsigned int color;
|
||||
float opacity;
|
||||
float saturation;
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
|
||||
Vertex(const glm::vec2& position, const glm::vec2& textureCoord, const unsigned int color)
|
||||
: position(position)
|
||||
, texture(textureCoord)
|
||||
, texcoord(textureCoord)
|
||||
, color(color)
|
||||
, opacity {1.0f}
|
||||
, saturation {1.0f}
|
||||
|
|
|
@ -116,10 +116,10 @@ void ShaderOpenGL::getVariableLocations(GLuint programID)
|
|||
{
|
||||
// Some of the variable names are chosen to be compatible with the RetroArch GLSL shaders.
|
||||
mShaderMVPMatrix = glGetUniformLocation(mProgramID, "MVPMatrix");
|
||||
mShaderPosition = glGetAttribLocation(mProgramID, "positionAttrib");
|
||||
mShaderTextureCoord = glGetAttribLocation(mProgramID, "TexCoord");
|
||||
mShaderColor = glGetAttribLocation(mProgramID, "colorAttrib");
|
||||
mShaderTextureSize = glGetUniformLocation(mProgramID, "TextureSize");
|
||||
mShaderPosition = glGetAttribLocation(mProgramID, "positionVertex");
|
||||
mShaderTextureCoord = glGetAttribLocation(mProgramID, "texCoordVertex");
|
||||
mShaderColor = glGetAttribLocation(mProgramID, "colorVertex");
|
||||
mShaderTextureSize = glGetUniformLocation(mProgramID, "textureSize");
|
||||
mShaderOpacity = glGetUniformLocation(mProgramID, "opacity");
|
||||
mShaderSaturation = glGetUniformLocation(mProgramID, "saturation");
|
||||
mShaderDimming = glGetUniformLocation(mProgramID, "dimming");
|
||||
|
@ -142,7 +142,7 @@ void ShaderOpenGL::setAttribPointers()
|
|||
if (mShaderTextureCoord != -1)
|
||||
GL_CHECK_ERROR(glVertexAttribPointer(
|
||||
mShaderTextureCoord, 2, GL_FLOAT, GL_FALSE, sizeof(Renderer::Vertex),
|
||||
reinterpret_cast<const void*>(offsetof(Renderer::Vertex, texture))));
|
||||
reinterpret_cast<const void*>(offsetof(Renderer::Vertex, texcoord))));
|
||||
|
||||
if (mShaderColor != -1)
|
||||
GL_CHECK_ERROR(glVertexAttribPointer(
|
||||
|
|
|
@ -9,124 +9,51 @@
|
|||
|
||||
#define HW 1.00
|
||||
|
||||
// Vertex section of code:
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec2 positionAttrib;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
uniform mat4 MVPMatrix;
|
||||
in vec2 positionVertex;
|
||||
in vec2 texCoordVertex;
|
||||
out vec2 texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * vec4(positionAttrib.xy, 0.0, 1.0);
|
||||
TEX0.xy = TexCoord.xy;
|
||||
gl_Position = MVPMatrix * vec4(positionVertex, 0.0, 1.0);
|
||||
texCoord = texCoordVertex;
|
||||
}
|
||||
|
||||
// Fragment section of code:
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
uniform vec2 textureSize;
|
||||
uniform sampler2D textureSampler;
|
||||
in vec2 texCoord;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING COMPAT_PRECISION vec4 TEX0;
|
||||
|
||||
// Compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) // Either TextureSize or InputSize.
|
||||
#define SourceSize vec4(textureSize, 1.0 / textureSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texcoord = vTexCoord;
|
||||
vec2 PIXEL_SIZE = vec2(SourceSize.z, SourceSize.w);
|
||||
|
||||
#if __VERSION__ < 130
|
||||
float sampleOffsets1 = 0.0;
|
||||
float sampleOffsets2 = 1.4347826;
|
||||
float sampleOffsets3 = 3.3478260;
|
||||
float sampleOffsets4 = 5.2608695;
|
||||
float sampleOffsets5 = 7.1739130;
|
||||
|
||||
float sampleWeights1 = 0.16818994;
|
||||
float sampleWeights2 = 0.27276957;
|
||||
float sampleWeights3 = 0.11690125;
|
||||
float sampleWeights4 = 0.024067905;
|
||||
float sampleWeights5 = 0.0021112196;
|
||||
|
||||
// Alpha is handled differently depending on the graphics driver, so set it explicitly to 1.0.
|
||||
vec4 color = COMPAT_TEXTURE(Source, texcoord);
|
||||
color = vec4(color.rgb, 1.0) * sampleWeights1;
|
||||
|
||||
color += COMPAT_TEXTURE(Source, texcoord + vec2(sampleOffsets2 * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights2;
|
||||
color += COMPAT_TEXTURE(Source, texcoord - vec2(sampleOffsets2 * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights2;
|
||||
|
||||
color += COMPAT_TEXTURE(Source, texcoord + vec2(sampleOffsets3 * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights3;
|
||||
color += COMPAT_TEXTURE(Source, texcoord - vec2(sampleOffsets3 * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights3;
|
||||
|
||||
color += COMPAT_TEXTURE(Source, texcoord + vec2(sampleOffsets4 * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights4;
|
||||
color += COMPAT_TEXTURE(Source, texcoord - vec2(sampleOffsets4 * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights4;
|
||||
|
||||
color += COMPAT_TEXTURE(Source, texcoord + vec2(sampleOffsets5 * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights5;
|
||||
color += COMPAT_TEXTURE(Source, texcoord - vec2(sampleOffsets5 * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights5;
|
||||
#else
|
||||
|
||||
float sampleOffsets[5] = float[5](0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130);
|
||||
float sampleWeights[5] =
|
||||
float[5](0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196);
|
||||
|
||||
vec4 color = COMPAT_TEXTURE(Source, texcoord) * sampleWeights[0];
|
||||
vec4 color = texture(textureSampler, texCoord) * sampleWeights[0];
|
||||
for (int i = 1; i < 5; i++) {
|
||||
color +=
|
||||
COMPAT_TEXTURE(Source, texcoord + vec2(sampleOffsets[i] * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
texture(textureSampler, texCoord + vec2(sampleOffsets[i] * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights[i];
|
||||
color +=
|
||||
COMPAT_TEXTURE(Source, texcoord - vec2(sampleOffsets[i] * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
texture(textureSampler, texCoord - vec2(sampleOffsets[i] * HW * PIXEL_SIZE.x, 0.0)) *
|
||||
sampleWeights[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
FragColor = vec4(color);
|
||||
}
|
||||
|
|
|
@ -9,124 +9,51 @@
|
|||
|
||||
#define VW 1.00
|
||||
|
||||
// Vertex section of code:
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec2 positionAttrib;
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
uniform mat4 MVPMatrix;
|
||||
in vec2 positionVertex;
|
||||
in vec2 texCoordVertex;
|
||||
out vec2 texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * vec4(positionAttrib.xy, 0.0, 1.0);
|
||||
TEX0.xy = TexCoord.xy;
|
||||
gl_Position = MVPMatrix * vec4(positionVertex, 0.0, 1.0);
|
||||
texCoord = texCoordVertex;
|
||||
}
|
||||
|
||||
// Fragment section of code:
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
uniform vec2 textureSize;
|
||||
uniform sampler2D textureSampler;
|
||||
in vec2 texCoord;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING COMPAT_PRECISION vec4 TEX0;
|
||||
|
||||
// compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) // Either TextureSize or InputSize.
|
||||
#define SourceSize vec4(textureSize, 1.0 / textureSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texcoord = vTexCoord;
|
||||
vec2 PIXEL_SIZE = vec2(SourceSize.z, SourceSize.w);
|
||||
|
||||
#if __VERSION__ < 130
|
||||
float sampleOffsets1 = 0.0;
|
||||
float sampleOffsets2 = 1.4347826;
|
||||
float sampleOffsets3 = 3.3478260;
|
||||
float sampleOffsets4 = 5.2608695;
|
||||
float sampleOffsets5 = 7.1739130;
|
||||
|
||||
float sampleWeights1 = 0.16818994;
|
||||
float sampleWeights2 = 0.27276957;
|
||||
float sampleWeights3 = 0.11690125;
|
||||
float sampleWeights4 = 0.024067905;
|
||||
float sampleWeights5 = 0.0021112196;
|
||||
|
||||
// Alpha is handled differently depending on the graphics driver, so set it explicitly to 1.0.
|
||||
vec4 color = COMPAT_TEXTURE(Source, texcoord);
|
||||
color = vec4(color.rgb, 1.0) * sampleWeights1;
|
||||
|
||||
color += COMPAT_TEXTURE(Source, texcoord + vec2(0.0, sampleOffsets2 * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights2;
|
||||
color += COMPAT_TEXTURE(Source, texcoord - vec2(0.0, sampleOffsets2 * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights2;
|
||||
|
||||
color += COMPAT_TEXTURE(Source, texcoord + vec2(0.0, sampleOffsets3 * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights3;
|
||||
color += COMPAT_TEXTURE(Source, texcoord - vec2(0.0, sampleOffsets3 * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights3;
|
||||
|
||||
color += COMPAT_TEXTURE(Source, texcoord + vec2(0.0, sampleOffsets4 * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights4;
|
||||
color += COMPAT_TEXTURE(Source, texcoord - vec2(0.0, sampleOffsets4 * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights4;
|
||||
|
||||
color += COMPAT_TEXTURE(Source, texcoord + vec2(0.0, sampleOffsets5 * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights5;
|
||||
color += COMPAT_TEXTURE(Source, texcoord - vec2(0.0, sampleOffsets5 * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights5;
|
||||
#else
|
||||
|
||||
float sampleOffsets[5] = float[5](0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130);
|
||||
float sampleWeights[5] =
|
||||
float[5](0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196);
|
||||
|
||||
vec4 color = COMPAT_TEXTURE(Source, texcoord) * sampleWeights[0];
|
||||
vec4 color = texture(textureSampler, texCoord) * sampleWeights[0];
|
||||
for (int i = 1; i < 5; i++) {
|
||||
color +=
|
||||
COMPAT_TEXTURE(Source, texcoord + vec2(0.0, sampleOffsets[i] * VW * PIXEL_SIZE.y)) *
|
||||
texture(textureSampler, texCoord + vec2(0.0, sampleOffsets[i] * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights[i];
|
||||
color +=
|
||||
COMPAT_TEXTURE(Source, texcoord - vec2(0.0, sampleOffsets[i] * VW * PIXEL_SIZE.y)) *
|
||||
texture(textureSampler, texCoord - vec2(0.0, sampleOffsets[i] * VW * PIXEL_SIZE.y)) *
|
||||
sampleWeights[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
FragColor = vec4(color);
|
||||
}
|
||||
|
|
|
@ -7,64 +7,40 @@
|
|||
// opacity, saturation, dimming and BGRA to RGBA conversion.
|
||||
//
|
||||
|
||||
#if defined(VERTEX)
|
||||
// Vertex section of code:
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
#if defined(VERTEX)
|
||||
|
||||
uniform mat4 MVPMatrix;
|
||||
COMPAT_ATTRIBUTE vec2 positionAttrib;
|
||||
COMPAT_ATTRIBUTE vec2 TexCoord;
|
||||
COMPAT_ATTRIBUTE vec4 colorAttrib;
|
||||
COMPAT_VARYING vec4 color;
|
||||
COMPAT_VARYING vec2 texCoord;
|
||||
in vec2 positionVertex;
|
||||
in vec2 texCoordVertex;
|
||||
in vec4 colorVertex;
|
||||
|
||||
out vec4 color;
|
||||
out vec2 texCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
color.rgba = colorAttrib.abgr;
|
||||
texCoord = TexCoord;
|
||||
gl_Position = MVPMatrix * vec4(positionAttrib.xy, 0.0, 1.0);
|
||||
gl_Position = MVPMatrix * vec4(positionVertex.xy, 0.0, 1.0);
|
||||
texCoord = texCoordVertex;
|
||||
color.rgba = colorVertex.abgr;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
// Fragment section of code:
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#define FragColor gl_FragColor
|
||||
#endif
|
||||
|
||||
COMPAT_VARYING COMPAT_PRECISION vec4 color;
|
||||
COMPAT_VARYING COMPAT_PRECISION vec4 color2;
|
||||
COMPAT_VARYING COMPAT_PRECISION vec2 texCoord;
|
||||
uniform COMPAT_PRECISION float opacity;
|
||||
uniform COMPAT_PRECISION float saturation;
|
||||
uniform COMPAT_PRECISION float dimming;
|
||||
in vec4 color;
|
||||
in vec2 texCoord;
|
||||
uniform float opacity;
|
||||
uniform float saturation;
|
||||
uniform float dimming;
|
||||
uniform unsigned int shaderFlags;
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
out vec4 FragColor;
|
||||
|
||||
// shaderFlags:
|
||||
// 0x00000001 - BGRA to RGBA conversion
|
||||
|
@ -73,33 +49,33 @@ uniform sampler2D textureSampler;
|
|||
|
||||
void main()
|
||||
{
|
||||
COMPAT_PRECISION vec4 sampledColor = COMPAT_TEXTURE(textureSampler, texCoord);
|
||||
vec4 sampledColor = texture(textureSampler, texCoord);
|
||||
|
||||
// For fonts the alpha information is stored in the red channel.
|
||||
if (0u != (shaderFlags & 2u))
|
||||
sampledColor = vec4(1.0f, 1.0f, 1.0f, sampledColor.r);
|
||||
sampledColor = vec4(1.0, 1.0, 1.0, sampledColor.r);
|
||||
|
||||
sampledColor *= color;
|
||||
|
||||
// When post-processing we drop the alpha channel to avoid strange issues
|
||||
// with some graphics drivers.
|
||||
if (0u != (shaderFlags & 4u))
|
||||
sampledColor.a = 1.0f;
|
||||
sampledColor.a = 1.0;
|
||||
|
||||
// Opacity.
|
||||
if (opacity != 1.0f)
|
||||
if (opacity != 1.0)
|
||||
sampledColor.a = sampledColor.a * opacity;
|
||||
|
||||
// Saturation.
|
||||
if (saturation != 1.0f) {
|
||||
COMPAT_PRECISION vec3 grayscale = vec3(dot(sampledColor.rgb, vec3(0.34f, 0.55f, 0.11f)));
|
||||
COMPAT_PRECISION vec3 blendedColor = mix(grayscale, sampledColor.rgb, saturation);
|
||||
if (saturation != 1.0) {
|
||||
vec3 grayscale = vec3(dot(sampledColor.rgb, vec3(0.34, 0.55, 0.11)));
|
||||
vec3 blendedColor = mix(grayscale, sampledColor.rgb, saturation);
|
||||
sampledColor = vec4(blendedColor, sampledColor.a);
|
||||
}
|
||||
|
||||
// Dimming
|
||||
if (dimming != 1.0f) {
|
||||
COMPAT_PRECISION vec4 dimColor = vec4(dimming, dimming, dimming, 1.0f);
|
||||
if (dimming != 1.0) {
|
||||
vec4 dimColor = vec4(dimming, dimming, dimming, 1.0);
|
||||
sampledColor *= dimColor;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,85 +20,54 @@
|
|||
// Taken from the RetroArch project and modified for ES-DE.
|
||||
//
|
||||
|
||||
// Vertex section of code:
|
||||
#if defined(VERTEX)
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING out
|
||||
#define COMPAT_ATTRIBUTE in
|
||||
#define COMPAT_TEXTURE texture
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define COMPAT_ATTRIBUTE attribute
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
COMPAT_ATTRIBUTE vec4 TexCoord;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
COMPAT_VARYING vec2 onex;
|
||||
COMPAT_VARYING vec2 oney;
|
||||
|
||||
uniform mat4 MVPMatrix;
|
||||
COMPAT_ATTRIBUTE vec2 positionAttrib;
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
in vec2 positionVertex;
|
||||
in vec2 texCoordVertex;
|
||||
uniform vec2 textureSize;
|
||||
out vec2 texCoord;
|
||||
out vec2 onex;
|
||||
out vec2 oney;
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) // Either TextureSize or InputSize.
|
||||
#define SourceSize vec4(textureSize, 1.0 / textureSize)
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVPMatrix * vec4(positionAttrib.xy, 0.0, 1.0);
|
||||
TEX0.xy = TexCoord.xy;
|
||||
gl_Position = MVPMatrix * vec4(positionVertex, 0.0, 1.0);
|
||||
texCoord = texCoordVertex;
|
||||
onex = vec2(SourceSize.z, 0.0);
|
||||
oney = vec2(0.0, SourceSize.w);
|
||||
}
|
||||
|
||||
// Fragment section of code:
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
#ifdef GL_ES
|
||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||
precision highp float;
|
||||
#else
|
||||
precision mediump float;
|
||||
#endif
|
||||
#define COMPAT_PRECISION mediump
|
||||
#else
|
||||
#define COMPAT_PRECISION
|
||||
#endif
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
#define COMPAT_VARYING in
|
||||
#define COMPAT_TEXTURE texture
|
||||
out COMPAT_PRECISION vec4 FragColor;
|
||||
#else
|
||||
#define COMPAT_VARYING varying
|
||||
#define FragColor gl_FragColor
|
||||
#define COMPAT_TEXTURE texture2D
|
||||
#endif
|
||||
uniform vec2 textureSize;
|
||||
uniform float opacity;
|
||||
uniform sampler2D textureSampler;
|
||||
in vec2 texCoord;
|
||||
in vec2 onex;
|
||||
in vec2 oney;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform COMPAT_PRECISION vec2 TextureSize;
|
||||
uniform COMPAT_PRECISION float opacity;
|
||||
uniform sampler2D Texture;
|
||||
COMPAT_VARYING vec4 TEX0;
|
||||
COMPAT_VARYING vec2 onex;
|
||||
COMPAT_VARYING vec2 oney;
|
||||
|
||||
// Compatibility #defines
|
||||
#define Source Texture
|
||||
#define vTexCoord TEX0.xy
|
||||
|
||||
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) // Either TextureSize or InputSize.
|
||||
#define SourceSize vec4(textureSize, 1.0 / textureSize)
|
||||
|
||||
#ifdef PARAMETER_UNIFORM
|
||||
// All parameter floats need to have COMPAT_PRECISION in front of them.
|
||||
uniform COMPAT_PRECISION float SPOT_WIDTH;
|
||||
uniform COMPAT_PRECISION float SPOT_HEIGHT;
|
||||
uniform COMPAT_PRECISION float COLOR_BOOST;
|
||||
uniform COMPAT_PRECISION float InputGamma;
|
||||
uniform COMPAT_PRECISION float OutputGamma;
|
||||
uniform float SPOT_WIDTH;
|
||||
uniform float SPOT_HEIGHT;
|
||||
uniform float COLOR_BOOST;
|
||||
uniform float InputGamma;
|
||||
uniform float OutputGamma;
|
||||
#else
|
||||
#define SPOT_WIDTH 0.9
|
||||
#define SPOT_HEIGHT 0.75
|
||||
|
@ -110,7 +79,7 @@ uniform COMPAT_PRECISION float OutputGamma;
|
|||
#define GAMMA_IN(color) pow(color, vec4(InputGamma))
|
||||
#define GAMMA_OUT(color) pow(color, vec4(1.0 / OutputGamma))
|
||||
|
||||
#define TEX2D(coords) GAMMA_IN(COMPAT_TEXTURE(Source, coords))
|
||||
#define TEX2D(coords) GAMMA_IN(texture(textureSampler, coords))
|
||||
|
||||
// Macro for weights computing.
|
||||
#define WEIGHT(w) \
|
||||
|
@ -121,7 +90,7 @@ uniform COMPAT_PRECISION float OutputGamma;
|
|||
|
||||
void main()
|
||||
{
|
||||
vec2 coords = (vTexCoord * SourceSize.xy);
|
||||
vec2 coords = (texCoord * SourceSize.xy);
|
||||
vec2 pixel_center = floor(coords) + vec2(0.5, 0.5);
|
||||
vec2 texture_coords = pixel_center * SourceSize.zw;
|
||||
|
||||
|
@ -156,7 +125,7 @@ void main()
|
|||
WEIGHT(v_weight_00);
|
||||
color *= vec4(v_weight_00);
|
||||
|
||||
// get closest vertical neighbour to blend
|
||||
// Get closest vertical neighbour to blend.
|
||||
vec2 coords10;
|
||||
if (dy > 0.0) {
|
||||
coords10 = oney;
|
||||
|
|
Loading…
Reference in a new issue