Skip to content

Commit

Permalink
Renderer|Client: Updated existing GLSL shaders to version 3.3
Browse files Browse the repository at this point in the history
Also added a new shader for old DGL drawing routines.
  • Loading branch information
skyjake committed Apr 23, 2017
1 parent 2359abb commit d7b67bd
Show file tree
Hide file tree
Showing 20 changed files with 542 additions and 451 deletions.
Expand Up @@ -8,15 +8,15 @@ shader fx.lensflares {
uniform sampler2D uTex;
uniform sampler2D uDepthBuf;

varying highp vec4 vColor;
varying highp vec2 vUV;
in vec4 vColor;
in vec2 vUV;

void main(void) {
highp vec4 tex = texture2D(uTex, vUV);
gl_FragColor = tex * vColor;
vec4 tex = texture(uTex, vUV);
out_FragColor = tex * vColor;

// Discard fragments without alpha.
if(gl_FragColor.a <= 0.0) {
if (out_FragColor.a <= 0.0) {
discard;
}
}"
Expand Down
@@ -1,35 +1,35 @@
uniform highp mat4 uMvpMatrix;
uniform highp vec4 uActiveRect; // (x-scale, y-scale, x-offset, y-offset)
uniform highp vec2 uViewUnit;
uniform highp vec2 uPixelAsUv;
uniform mat4 uMvpMatrix;
uniform vec4 uActiveRect; // (x-scale, y-scale, x-offset, y-offset)
uniform vec2 uViewUnit;
uniform vec2 uPixelAsUv;
uniform sampler2D uDepthBuf;

attribute highp vec4 aVertex;
attribute highp vec4 aColor;
attribute highp vec2 aUV;
attribute highp vec2 aUV2;
attribute highp vec2 aUV3;
in vec4 aVertex;
in vec4 aColor;
in vec2 aUV;
in vec2 aUV2;
in vec2 aUV3;

varying highp vec4 vColor;
varying highp vec2 vUV;
out vec4 vColor;
out vec2 vUV;

bool isOccluded(highp vec2 uv) {
bool isOccluded(vec2 uv) {
// Apply a possible viewport transformation.
uv = uv * uActiveRect.xy + uActiveRect.zw;

float depth = texture2D(uDepthBuf, uv).r;
float depth = texture(uDepthBuf, uv).r;
return (depth < (gl_Position.z/gl_Position.w + 1.0) / 2.0);
}

float occlusionLevel() {
highp vec2 depthUv = gl_Position.xy / gl_Position.w / 2.0 + vec2(0.5, 0.5);
vec2 depthUv = gl_Position.xy / gl_Position.w / 2.0 + vec2(0.5, 0.5);

float occ = 0.0;
if(!isOccluded(depthUv)) occ += 0.2;
if(!isOccluded(depthUv + vec2(uPixelAsUv.x * 4.0, uPixelAsUv.y))) occ += 0.2;
if(!isOccluded(depthUv - vec2(uPixelAsUv.x * 4.0, uPixelAsUv.y))) occ += 0.2;
if(!isOccluded(depthUv + vec2(uPixelAsUv.x, uPixelAsUv.y * 4.0))) occ += 0.2;
if(!isOccluded(depthUv - vec2(uPixelAsUv.x, uPixelAsUv.y * 4.0))) occ += 0.2;
if (!isOccluded(depthUv)) occ += 0.2;
if (!isOccluded(depthUv + vec2(uPixelAsUv.x * 4.0, uPixelAsUv.y))) occ += 0.2;
if (!isOccluded(depthUv - vec2(uPixelAsUv.x * 4.0, uPixelAsUv.y))) occ += 0.2;
if (!isOccluded(depthUv + vec2(uPixelAsUv.x, uPixelAsUv.y * 4.0))) occ += 0.2;
if (!isOccluded(depthUv - vec2(uPixelAsUv.x, uPixelAsUv.y * 4.0))) occ += 0.2;
return occ;
}

Expand All @@ -41,7 +41,7 @@ void main(void) {

// Is the origin occluded in the depth buffer?
float ocl = occlusionLevel();
if(ocl <= 0.0) {
if (ocl <= 0.0) {
// Occluded! Make it invisibile and leave the quad zero-sized.
vUV = aUV;
vColor = vec4(0.0, 0.0, 0.0, 0.0);
Expand All @@ -52,7 +52,7 @@ void main(void) {
}

// Position on the axis that passes through the center of the view.
highp float axisPos = aUV3.s;
float axisPos = aUV3.s;
gl_Position.xy *= axisPos;

// Position the quad corners.
Expand Down
Expand Up @@ -8,6 +8,7 @@
# - vertex: source of the vertex shader
# - fragment: source of the fragment shader

@include <shaders/dgl/dgl.dei>
@include <shaders/generic.dei>
@include <shaders/model.dei>
@include <shaders/fx/blur.dei>
Expand Down
Expand Up @@ -3,12 +3,12 @@ debug {
# Visualize alpha information.
shader alpha {
vertex = "
uniform highp mat4 uMvpMatrix;
attribute highp vec4 aVertex;
attribute highp vec2 aUV;
attribute highp vec4 aColor;
varying highp vec2 vUV;
varying highp vec4 vColor;
uniform mat4 uMvpMatrix;
in vec4 aVertex;
in vec2 aUV;
in vec4 aColor;
out vec2 vUV;
out vec4 vColor;

void main(void) {
gl_Position = uMvpMatrix * aVertex;
Expand All @@ -17,12 +17,12 @@ debug {
}"
fragment = "
uniform sampler2D uTex;
varying highp vec2 vUV;
varying highp vec4 vColor;
in vec2 vUV;
in vec4 vColor;

void main(void) {
highp vec4 col = vColor * texture2D(uTex, vUV);
gl_FragColor = vec4(col.a, col.a, col.a, 1.0);
vec4 col = vColor * texture(uTex, vUV);
out_FragColor = vec4(col.a, col.a, col.a, 1.0);
}"
}
}
Expand Down
@@ -0,0 +1,5 @@
# Shader for the DGL drawing routines that emulate OpenGL 1.x behavior.
shader dgl.draw {
vertex.path = "dgl_draw.vsh"
fragment.path = "dgl_draw.fsh"
}
@@ -0,0 +1,50 @@
/*
* The Doomsday Engine Project
* Common OpenGL Shaders: Legacy DGL Drawing
*
* Copyright (c) 2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#version 330

uniform int uEnabledTextures;
uniform sampler2D uTex0;
uniform sampler2D uTex1;
uniform sampler2D uTex2;

in vec4 vColor;
in vec2 vTexCoord[3];

void main()
{
out_FragColor = vColor;

// Colors from textures.
vec4 texColor[3] = vec4[3] (vec4(0.0), vec4(0.0), vec4(0.0));
if ((uEnabledTextures & 0x1) != 0) {
texColor[0] = texture(uTex0, vTexCoord[0]);
out_FragColor *= texColor[0];
}
if ((uEnabledTextures & 0x2) != 0) {
texColor[1] = texture(uTex1, vTexCoord[1]);
}
if ((uEnabledTextures & 0x4) != 0) {
texColor[2] = texture(uTex2, vTexCoord[2]);
}

// TODO: Modulate the texture colors in the requested manner

}
@@ -0,0 +1,46 @@
/*
* The Doomsday Engine Project
* Common OpenGL Shaders: Legacy DGL Drawing
*
* Copyright (c) 2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#version 330

layout(location = 0) in vec3 aVertex;
layout(location = 1) in vec4 aColor;
layout(location = 2) in vec2 aTexCoord[3];

uniform mat4 uMvpMatrix;
uniform mat4 uTextureMatrix;

out vec4 vColor;
out vec2 vTexCoord[3];

vec2 transformTexCoord(vec2 tc)
{
vec4 coord = vec4(tc.s, tc.t, 0.0, 1.0);
return (uTextureMatrix * coord).xy;
}

void main()
{
gl_Position = uMvpMatrix * aVertex;
vColor = aColor;
for (int i = 0; i < 3; ++i) {
vTexCoord[i] = transformTexCoord(aTexCoord[i]);
}
}
Expand Up @@ -2,14 +2,14 @@
# (given a configurable threshold for brightness).
fx.bloom {
common = "
uniform highp mat4 uMvpMatrix;
uniform highp vec4 uColor;
uniform highp vec4 uWindow;
uniform mat4 uMvpMatrix;
uniform vec4 uColor;
uniform vec4 uWindow;

attribute highp vec4 aVertex;
attribute highp vec2 aUV;
in vec4 aVertex;
in vec2 aUV;

varying highp vec2 vUV;
out vec2 vUV;

void main(void) {
gl_Position = uMvpMatrix * aVertex;
Expand All @@ -20,68 +20,68 @@ fx.bloom {
vertex $= fx.bloom.common
fragment = "
uniform sampler2D uTex;
uniform highp float uIntensity;
uniform highp float uThreshold;
uniform highp vec2 uBlurStep;
uniform float uIntensity;
uniform float uThreshold;
uniform vec2 uBlurStep;

varying highp vec2 vUV;
in vec2 vUV;

void main(void) {
highp vec4 sum = vec4(0.0);
vec4 sum = vec4(0.0);

sum += texture2D(uTex, vec2(vUV.s - 7.0 * uBlurStep.s, vUV.t)) * 0.0249;
sum += texture2D(uTex, vec2(vUV.s - 6.0 * uBlurStep.s, vUV.t)) * 0.0367;
sum += texture2D(uTex, vec2(vUV.s - 5.0 * uBlurStep.s, vUV.t)) * 0.0498;
sum += texture2D(uTex, vec2(vUV.s - 4.0 * uBlurStep.s, vUV.t)) * 0.0660;
sum += texture2D(uTex, vec2(vUV.s - 3.0 * uBlurStep.s, vUV.t)) * 0.0803;
sum += texture2D(uTex, vec2(vUV.s - 2.0 * uBlurStep.s, vUV.t)) * 0.0915;
sum += texture2D(uTex, vec2(vUV.s - uBlurStep.s, vUV.t)) * 0.0996;
sum += texture2D(uTex, vUV) * 0.1027;
sum += texture2D(uTex, vec2(vUV.s + uBlurStep.s, vUV.t)) * 0.0996;
sum += texture2D(uTex, vec2(vUV.s + 2.0 * uBlurStep.s, vUV.t)) * 0.0915;
sum += texture2D(uTex, vec2(vUV.s + 3.0 * uBlurStep.s, vUV.t)) * 0.0803;
sum += texture2D(uTex, vec2(vUV.s + 4.0 * uBlurStep.s, vUV.t)) * 0.0660;
sum += texture2D(uTex, vec2(vUV.s + 5.0 * uBlurStep.s, vUV.t)) * 0.0498;
sum += texture2D(uTex, vec2(vUV.s + 6.0 * uBlurStep.s, vUV.t)) * 0.0367;
sum += texture2D(uTex, vec2(vUV.s + 7.0 * uBlurStep.s, vUV.t)) * 0.0249;
sum += texture(uTex, vec2(vUV.s - 7.0 * uBlurStep.s, vUV.t)) * 0.0249;
sum += texture(uTex, vec2(vUV.s - 6.0 * uBlurStep.s, vUV.t)) * 0.0367;
sum += texture(uTex, vec2(vUV.s - 5.0 * uBlurStep.s, vUV.t)) * 0.0498;
sum += texture(uTex, vec2(vUV.s - 4.0 * uBlurStep.s, vUV.t)) * 0.0660;
sum += texture(uTex, vec2(vUV.s - 3.0 * uBlurStep.s, vUV.t)) * 0.0803;
sum += texture(uTex, vec2(vUV.s - 2.0 * uBlurStep.s, vUV.t)) * 0.0915;
sum += texture(uTex, vec2(vUV.s - uBlurStep.s, vUV.t)) * 0.0996;
sum += texture(uTex, vUV) * 0.1027;
sum += texture(uTex, vec2(vUV.s + uBlurStep.s, vUV.t)) * 0.0996;
sum += texture(uTex, vec2(vUV.s + 2.0 * uBlurStep.s, vUV.t)) * 0.0915;
sum += texture(uTex, vec2(vUV.s + 3.0 * uBlurStep.s, vUV.t)) * 0.0803;
sum += texture(uTex, vec2(vUV.s + 4.0 * uBlurStep.s, vUV.t)) * 0.0660;
sum += texture(uTex, vec2(vUV.s + 5.0 * uBlurStep.s, vUV.t)) * 0.0498;
sum += texture(uTex, vec2(vUV.s + 6.0 * uBlurStep.s, vUV.t)) * 0.0367;
sum += texture(uTex, vec2(vUV.s + 7.0 * uBlurStep.s, vUV.t)) * 0.0249;

// Apply a threshold that gets rid of dark, non-luminous pixels.
highp float intens = max(sum.r, max(sum.g, sum.b));
float intens = max(sum.r, max(sum.g, sum.b));

intens = (intens - uThreshold) * uIntensity;

gl_FragColor = vec4(vec3(intens) * normalize(sum.rgb + 0.2), 1.0);
out_FragColor = vec4(vec3(intens) * normalize(sum.rgb + 0.2), 1.0);
}"
}

shader vertical {
vertex $= fx.bloom.common
fragment = "
uniform sampler2D uTex;
uniform highp vec2 uBlurStep;
uniform vec2 uBlurStep;

varying highp vec2 vUV;
in vec2 vUV;

void main(void) {
highp vec4 sum = vec4(0.0);
vec4 sum = vec4(0.0);

sum += texture2D(uTex, vec2(vUV.s, vUV.t - 7.0 * uBlurStep.t)) * 0.0249;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - 6.0 * uBlurStep.t)) * 0.0367;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - 5.0 * uBlurStep.t)) * 0.0498;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - 4.0 * uBlurStep.t)) * 0.0660;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - 3.0 * uBlurStep.t)) * 0.0803;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - 2.0 * uBlurStep.t)) * 0.0915;
sum += texture2D(uTex, vec2(vUV.s, vUV.t - uBlurStep.t )) * 0.0996;
sum += texture2D(uTex, vUV) * 0.1027;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + uBlurStep.t )) * 0.0996;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 2.0 * uBlurStep.t)) * 0.0915;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 3.0 * uBlurStep.t)) * 0.0803;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 4.0 * uBlurStep.t)) * 0.0660;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 5.0 * uBlurStep.t)) * 0.0498;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 6.0 * uBlurStep.t)) * 0.0367;
sum += texture2D(uTex, vec2(vUV.s, vUV.t + 7.0 * uBlurStep.t)) * 0.0249;
sum += texture(uTex, vec2(vUV.s, vUV.t - 7.0 * uBlurStep.t)) * 0.0249;
sum += texture(uTex, vec2(vUV.s, vUV.t - 6.0 * uBlurStep.t)) * 0.0367;
sum += texture(uTex, vec2(vUV.s, vUV.t - 5.0 * uBlurStep.t)) * 0.0498;
sum += texture(uTex, vec2(vUV.s, vUV.t - 4.0 * uBlurStep.t)) * 0.0660;
sum += texture(uTex, vec2(vUV.s, vUV.t - 3.0 * uBlurStep.t)) * 0.0803;
sum += texture(uTex, vec2(vUV.s, vUV.t - 2.0 * uBlurStep.t)) * 0.0915;
sum += texture(uTex, vec2(vUV.s, vUV.t - uBlurStep.t )) * 0.0996;
sum += texture(uTex, vUV) * 0.1027;
sum += texture(uTex, vec2(vUV.s, vUV.t + uBlurStep.t )) * 0.0996;
sum += texture(uTex, vec2(vUV.s, vUV.t + 2.0 * uBlurStep.t)) * 0.0915;
sum += texture(uTex, vec2(vUV.s, vUV.t + 3.0 * uBlurStep.t)) * 0.0803;
sum += texture(uTex, vec2(vUV.s, vUV.t + 4.0 * uBlurStep.t)) * 0.0660;
sum += texture(uTex, vec2(vUV.s, vUV.t + 5.0 * uBlurStep.t)) * 0.0498;
sum += texture(uTex, vec2(vUV.s, vUV.t + 6.0 * uBlurStep.t)) * 0.0367;
sum += texture(uTex, vec2(vUV.s, vUV.t + 7.0 * uBlurStep.t)) * 0.0249;

gl_FragColor = sum;
out_FragColor = sum;
}"
}
}

0 comments on commit d7b67bd

Please sign in to comment.