-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #396 from avaraline/deferred-rendering
Rendering updates (better alpha support)
- Loading branch information
Showing
21 changed files
with
508 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#version 330 core | ||
|
||
in vec2 texCoords; | ||
|
||
uniform sampler2D screenTexture; | ||
uniform int fxaa; | ||
uniform vec2 texelStep; | ||
uniform float lumaThreshold; | ||
uniform float mulReduce; | ||
uniform float minReduce; | ||
uniform float maxSpan; | ||
|
||
out vec4 color; | ||
|
||
void main() | ||
{ | ||
vec3 rgbM = texture(screenTexture, texCoords).rgb; | ||
|
||
// Possibility to toggle FXAA on and off. | ||
if (fxaa == 0) | ||
{ | ||
color = vec4(rgbM, 1.0); | ||
|
||
return; | ||
} | ||
|
||
// Sampling neighbour texels. Offsets are adapted to OpenGL texture coordinates. | ||
vec3 rgbNW = textureOffset(screenTexture, texCoords, ivec2(-1, 1)).rgb; | ||
vec3 rgbNE = textureOffset(screenTexture, texCoords, ivec2(1, 1)).rgb; | ||
vec3 rgbSW = textureOffset(screenTexture, texCoords, ivec2(-1, -1)).rgb; | ||
vec3 rgbSE = textureOffset(screenTexture, texCoords, ivec2(1, -1)).rgb; | ||
|
||
// see http://en.wikipedia.org/wiki/Grayscale | ||
const vec3 toLuma = vec3(0.299, 0.587, 0.114); | ||
|
||
// Convert from RGB to luma. | ||
float lumaNW = dot(rgbNW, toLuma); | ||
float lumaNE = dot(rgbNE, toLuma); | ||
float lumaSW = dot(rgbSW, toLuma); | ||
float lumaSE = dot(rgbSE, toLuma); | ||
float lumaM = dot(rgbM, toLuma); | ||
|
||
// Gather minimum and maximum luma. | ||
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); | ||
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); | ||
|
||
// If contrast is lower than a maximum threshold ... | ||
if (lumaMax - lumaMin <= lumaMax * lumaThreshold) | ||
{ | ||
// ... do no AA and return. | ||
color = vec4(rgbM, 1.0); | ||
|
||
return; | ||
} | ||
|
||
// Sampling is done along the gradient. | ||
vec2 samplingDirection; | ||
samplingDirection.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); | ||
samplingDirection.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); | ||
|
||
// Sampling step distance depends on the luma: The brighter the sampled texels, the smaller the final sampling step direction. | ||
// This results, that brighter areas are less blurred/more sharper than dark areas. | ||
float samplingDirectionReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * 0.25 * mulReduce, minReduce); | ||
|
||
// Factor for norming the sampling direction plus adding the brightness influence. | ||
float minSamplingDirectionFactor = 1.0 / (min(abs(samplingDirection.x), abs(samplingDirection.y)) + samplingDirectionReduce); | ||
|
||
// Calculate final sampling direction vector by reducing, clamping to a range and finally adapting to the texture size. | ||
samplingDirection = clamp(samplingDirection * minSamplingDirectionFactor, vec2(-maxSpan), vec2(maxSpan)) * texelStep; | ||
|
||
// Inner samples on the tab. | ||
vec3 rgbSampleNeg = texture(screenTexture, texCoords + samplingDirection * (1.0/3.0 - 0.5)).rgb; | ||
vec3 rgbSamplePos = texture(screenTexture, texCoords + samplingDirection * (2.0/3.0 - 0.5)).rgb; | ||
|
||
vec3 rgbTwoTab = (rgbSamplePos + rgbSampleNeg) * 0.5; | ||
|
||
// Outer samples on the tab. | ||
vec3 rgbSampleNegOuter = texture(screenTexture, texCoords + samplingDirection * (0.0/3.0 - 0.5)).rgb; | ||
vec3 rgbSamplePosOuter = texture(screenTexture, texCoords + samplingDirection * (3.0/3.0 - 0.5)).rgb; | ||
|
||
vec3 rgbFourTab = (rgbSamplePosOuter + rgbSampleNegOuter) * 0.25 + rgbTwoTab * 0.5; | ||
|
||
// Calculate luma for checking against the minimum and maximum value. | ||
float lumaFourTab = dot(rgbFourTab, toLuma); | ||
|
||
// Are outer samples of the tab beyond the edge ... | ||
if (lumaFourTab < lumaMin || lumaFourTab > lumaMax) | ||
{ | ||
// ... yes, so use only two samples. | ||
color = vec4(rgbTwoTab, 1.0); | ||
} | ||
else | ||
{ | ||
// ... no, so use four samples. | ||
color = vec4(rgbFourTab, 1.0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#version 330 core | ||
|
||
layout (location = 0) in vec2 aPos; | ||
layout (location = 1) in vec2 aTexCoords; | ||
|
||
out vec2 texCoords; | ||
|
||
void main() | ||
{ | ||
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); | ||
texCoords = aTexCoords; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#version 330 core | ||
|
||
in vec2 texCoords; | ||
|
||
uniform float hudAlpha = 1.0; | ||
uniform sampler2D screenTexture; | ||
|
||
out vec4 color; | ||
|
||
void main() | ||
{ | ||
color = texture(screenTexture, texCoords); | ||
color[3] *= hudAlpha; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#version 330 core | ||
|
||
layout (location = 0) in vec2 aPos; | ||
layout (location = 1) in vec2 aTexCoords; | ||
|
||
out vec2 texCoords; | ||
|
||
void main() | ||
{ | ||
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); | ||
texCoords = aTexCoords; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#version 330 core | ||
|
||
in vec2 texCoords; | ||
|
||
uniform sampler2D screenTexture; | ||
|
||
out vec4 color; | ||
|
||
void main() | ||
{ | ||
color = texture(screenTexture, texCoords); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#version 330 core | ||
|
||
layout (location = 0) in vec2 aPos; | ||
layout (location = 1) in vec2 aTexCoords; | ||
|
||
out vec2 texCoords; | ||
|
||
void main() | ||
{ | ||
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); | ||
texCoords = aTexCoords; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.