mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-25 04:41:18 +00:00
Removed unused GLES shader files
This commit is contained in:
parent
6d8862b514
commit
c20cb92961
20 changed files with 0 additions and 1700 deletions
|
@ -1,195 +0,0 @@
|
|||
|
||||
const float PI = 3.14159265359;
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness * roughness;
|
||||
float a2 = a * a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float nom = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
{
|
||||
float r = (roughness + 1.0);
|
||||
float k = (r * r) / 8.0;
|
||||
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return nom / denom;
|
||||
}
|
||||
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0)
|
||||
{
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness)
|
||||
{
|
||||
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
float quadraticDistanceAttenuation(vec4 lightpos)
|
||||
{
|
||||
float strength = (1.0 + lightpos.w * lightpos.w * 0.25) * 0.5;
|
||||
|
||||
vec3 distVec = lightpos.xyz - pixelpos.xyz;
|
||||
float attenuation = strength / (1.0 + dot(distVec, distVec));
|
||||
if (attenuation <= 1.0 / 256.0) return 0.0;
|
||||
|
||||
return attenuation;
|
||||
}
|
||||
|
||||
float linearDistanceAttenuation(vec4 lightpos)
|
||||
{
|
||||
float lightdistance = distance(lightpos.xyz, pixelpos.xyz);
|
||||
return clamp((lightpos.w - lightdistance) / lightpos.w, 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 ProcessMaterialLight(Material material, vec3 ambientLight)
|
||||
{
|
||||
vec3 worldpos = pixelpos.xyz;
|
||||
|
||||
vec3 albedo = pow(material.Base.rgb, vec3(2.2)); // sRGB to linear
|
||||
ambientLight = pow(ambientLight, vec3(2.2));
|
||||
|
||||
float metallic = material.Metallic;
|
||||
float roughness = material.Roughness;
|
||||
float ao = material.AO;
|
||||
|
||||
vec3 N = material.Normal;
|
||||
vec3 V = normalize(uCameraPos.xyz - worldpos);
|
||||
|
||||
vec3 F0 = mix(vec3(0.04), albedo, metallic);
|
||||
|
||||
vec3 Lo = uDynLightColor.rgb;
|
||||
|
||||
if (uLightIndex >= 0)
|
||||
{
|
||||
ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
|
||||
if (lightRange.z > lightRange.x)
|
||||
{
|
||||
//
|
||||
// modulated lights
|
||||
//
|
||||
for(int i=lightRange.x; i<lightRange.y; i+=4)
|
||||
{
|
||||
vec4 lightpos = lights[i];
|
||||
vec4 lightcolor = lights[i+1];
|
||||
vec4 lightspot1 = lights[i+2];
|
||||
vec4 lightspot2 = lights[i+3];
|
||||
|
||||
vec3 L = normalize(lightpos.xyz - worldpos);
|
||||
vec3 H = normalize(V + L);
|
||||
|
||||
float attenuation = linearDistanceAttenuation(lightpos);
|
||||
if (lightspot1.w == 1.0)
|
||||
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
|
||||
if (lightcolor.a < 0.0)
|
||||
attenuation *= clamp(dot(N, L), 0.0, 1.0); // Sign bit is the attenuated light flag
|
||||
|
||||
if (attenuation > 0.0)
|
||||
{
|
||||
attenuation *= shadowAttenuation(lightpos, lightcolor.a);
|
||||
|
||||
vec3 radiance = lightcolor.rgb * attenuation;
|
||||
|
||||
// cook-torrance brdf
|
||||
float NDF = DistributionGGX(N, H, roughness);
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0);
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = (vec3(1.0) - kS) * (1.0 - metallic);
|
||||
|
||||
vec3 nominator = NDF * G * F;
|
||||
float denominator = 4.0 * clamp(dot(N, V), 0.0, 1.0) * clamp(dot(N, L), 0.0, 1.0);
|
||||
vec3 specular = nominator / max(denominator, 0.001);
|
||||
|
||||
Lo += (kD * albedo / PI + specular) * radiance;
|
||||
}
|
||||
}
|
||||
//
|
||||
// subtractive lights
|
||||
//
|
||||
for(int i=lightRange.y; i<lightRange.z; i+=4)
|
||||
{
|
||||
vec4 lightpos = lights[i];
|
||||
vec4 lightcolor = lights[i+1];
|
||||
vec4 lightspot1 = lights[i+2];
|
||||
vec4 lightspot2 = lights[i+3];
|
||||
|
||||
vec3 L = normalize(lightpos.xyz - worldpos);
|
||||
vec3 H = normalize(V + L);
|
||||
|
||||
float attenuation = linearDistanceAttenuation(lightpos);
|
||||
if (lightspot1.w == 1.0)
|
||||
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
|
||||
if (lightcolor.a < 0.0)
|
||||
attenuation *= clamp(dot(N, L), 0.0, 1.0); // Sign bit is the attenuated light flag
|
||||
|
||||
if (attenuation > 0.0)
|
||||
{
|
||||
attenuation *= shadowAttenuation(lightpos, lightcolor.a);
|
||||
|
||||
vec3 radiance = lightcolor.rgb * attenuation;
|
||||
|
||||
// cook-torrance brdf
|
||||
float NDF = DistributionGGX(N, H, roughness);
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0);
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = (vec3(1.0) - kS) * (1.0 - metallic);
|
||||
|
||||
vec3 nominator = NDF * G * F;
|
||||
float denominator = 4.0 * clamp(dot(N, V), 0.0, 1.0) * clamp(dot(N, L), 0.0, 1.0);
|
||||
vec3 specular = nominator / max(denominator, 0.001);
|
||||
|
||||
Lo -= (kD * albedo / PI + specular) * radiance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pretend we sampled the sector light level from an irradiance map
|
||||
|
||||
vec3 F = fresnelSchlickRoughness(clamp(dot(N, V), 0.0, 1.0), F0, roughness);
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = 1.0 - kS;
|
||||
|
||||
vec3 irradiance = ambientLight; // texture(irradianceMap, N).rgb
|
||||
vec3 diffuse = irradiance * albedo;
|
||||
|
||||
//kD *= 1.0 - metallic;
|
||||
//const float MAX_REFLECTION_LOD = 4.0;
|
||||
//vec3 prefilteredColor = textureLod(prefilterMap, R, roughness * MAX_REFLECTION_LOD).rgb;
|
||||
//vec2 envBRDF = texture(brdfLUT, vec2(clamp(dot(N, V), 0.0, 1.0), roughness)).rg;
|
||||
//vec3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
|
||||
|
||||
//vec3 ambient = (kD * diffuse + specular) * ao;
|
||||
vec3 ambient = (kD * diffuse) * ao;
|
||||
|
||||
vec3 color = max(ambient + Lo, vec3(0.0));
|
||||
|
||||
// Tonemap (reinhard) and apply sRGB gamma
|
||||
//color = color / (color + vec3(1.0));
|
||||
return pow(color, vec3(1.0 / 2.2));
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
|
||||
vec2 lightAttenuation(int i, vec3 normal, vec3 viewdir, float lightcolorA)
|
||||
{
|
||||
vec4 lightpos = lights[i];
|
||||
vec4 lightspot1 = lights[i+2];
|
||||
vec4 lightspot2 = lights[i+3];
|
||||
|
||||
float lightdistance = distance(lightpos.xyz, pixelpos.xyz);
|
||||
if (lightpos.w < lightdistance)
|
||||
return vec2(0.0); // Early out lights touching surface but not this fragment
|
||||
|
||||
float attenuation = clamp((lightpos.w - lightdistance) / lightpos.w, 0.0, 1.0);
|
||||
|
||||
if (lightspot1.w == 1.0)
|
||||
attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y);
|
||||
|
||||
vec3 lightdir = normalize(lightpos.xyz - pixelpos.xyz);
|
||||
|
||||
if (lightcolorA < 0.0) // Sign bit is the attenuated light flag
|
||||
attenuation *= clamp(dot(normal, lightdir), 0.0, 1.0);
|
||||
|
||||
if (attenuation > 0.0) // Skip shadow map test if possible
|
||||
attenuation *= shadowAttenuation(lightpos, lightcolorA);
|
||||
|
||||
if (attenuation <= 0.0)
|
||||
return vec2(0.0);
|
||||
|
||||
float glossiness = uSpecularMaterial.x;
|
||||
float specularLevel = uSpecularMaterial.y;
|
||||
|
||||
vec3 halfdir = normalize(viewdir + lightdir);
|
||||
float specAngle = clamp(dot(halfdir, normal), 0.0, 1.0);
|
||||
float phExp = glossiness * 4.0;
|
||||
return vec2(attenuation, attenuation * specularLevel * pow(specAngle, phExp));
|
||||
}
|
||||
|
||||
vec3 ProcessMaterialLight(Material material, vec3 color)
|
||||
{
|
||||
vec4 dynlight = uDynLightColor;
|
||||
vec4 specular = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
vec3 normal = material.Normal;
|
||||
vec3 viewdir = normalize(uCameraPos.xyz - pixelpos.xyz);
|
||||
|
||||
if (uLightIndex >= 0)
|
||||
{
|
||||
ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
|
||||
if (lightRange.z > lightRange.x)
|
||||
{
|
||||
// modulated lights
|
||||
for(int i=lightRange.x; i<lightRange.y; i+=4)
|
||||
{
|
||||
vec4 lightcolor = lights[i+1];
|
||||
vec2 attenuation = lightAttenuation(i, normal, viewdir, lightcolor.a);
|
||||
dynlight.rgb += lightcolor.rgb * attenuation.x;
|
||||
specular.rgb += lightcolor.rgb * attenuation.y;
|
||||
}
|
||||
|
||||
// subtractive lights
|
||||
for(int i=lightRange.y; i<lightRange.z; i+=4)
|
||||
{
|
||||
vec4 lightcolor = lights[i+1];
|
||||
vec2 attenuation = lightAttenuation(i, normal, viewdir, lightcolor.a);
|
||||
dynlight.rgb -= lightcolor.rgb * attenuation.x;
|
||||
specular.rgb -= lightcolor.rgb * attenuation.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dynlight.rgb = clamp(color + desaturate(dynlight).rgb, 0.0, 1.4);
|
||||
specular.rgb = clamp(desaturate(specular).rgb, 0.0, 1.4);
|
||||
|
||||
vec3 frag = material.Base.rgb * dynlight.rgb + material.Specular * specular.rgb;
|
||||
|
||||
if (uLightIndex >= 0)
|
||||
{
|
||||
ivec4 lightRange = ivec4(lights[uLightIndex]) + ivec4(uLightIndex + 1);
|
||||
if (lightRange.w > lightRange.z)
|
||||
{
|
||||
vec4 addlight = vec4(0.0,0.0,0.0,0.0);
|
||||
|
||||
// additive lights
|
||||
for(int i=lightRange.z; i<lightRange.w; i+=4)
|
||||
{
|
||||
vec4 lightcolor = lights[i+1];
|
||||
vec2 attenuation = lightAttenuation(i, normal, viewdir, lightcolor.a);
|
||||
addlight.rgb += lightcolor.rgb * attenuation.x;
|
||||
}
|
||||
|
||||
frag = clamp(frag + desaturate(addlight).rgb, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
return frag;
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D Bloom;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(texture(Bloom, TexCoord).rgb, 0.0);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
layout(binding=0) uniform sampler2D SceneTexture;
|
||||
layout(binding=1) uniform sampler2D ExposureTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
float exposureAdjustment = texture(ExposureTexture, vec2(0.5)).x;
|
||||
vec4 color = texture(SceneTexture, Offset + TexCoord * Scale);
|
||||
FragColor = max(vec4((color.rgb + vec3(0.001)) * exposureAdjustment - 1.0, 1.0), vec4(0));
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D SourceTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(BLUR_HORIZONTAL)
|
||||
FragColor =
|
||||
textureOffset(SourceTexture, TexCoord, ivec2( 0, 0)) * SampleWeights0 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2( 1, 0)) * SampleWeights1 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(-1, 0)) * SampleWeights2 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2( 2, 0)) * SampleWeights3 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(-2, 0)) * SampleWeights4 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2( 3, 0)) * SampleWeights5 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(-3, 0)) * SampleWeights6;
|
||||
#else
|
||||
FragColor =
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(0, 0)) * SampleWeights0 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(0, 1)) * SampleWeights1 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(0,-1)) * SampleWeights2 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(0, 2)) * SampleWeights3 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(0,-2)) * SampleWeights4 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(0, 3)) * SampleWeights5 +
|
||||
textureOffset(SourceTexture, TexCoord, ivec2(0,-3)) * SampleWeights6;
|
||||
#endif
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
layout(binding=0) uniform sampler2D SceneTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 frag = texture(SceneTexture, TexCoord);
|
||||
frag.rgb = clamp(pow(frag.rgb, vec3(uFixedColormapStart.a)), 0.0, 1.0);
|
||||
if (uFixedColormapRange.a == 0.0)
|
||||
{
|
||||
float gray = (frag.r * 0.3 + frag.g * 0.56 + frag.b * 0.14);
|
||||
vec4 cm = uFixedColormapStart + gray * uFixedColormapRange;
|
||||
frag.rgb = clamp(cm.rgb, 0.0, 1.0);
|
||||
}
|
||||
FragColor = frag;
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D AODepthTexture;
|
||||
|
||||
#define KERNEL_RADIUS 3.0
|
||||
|
||||
void AddSample(vec2 blurSample, float r, float centerDepth, inout float totalAO, inout float totalW)
|
||||
{
|
||||
const float blurSigma = KERNEL_RADIUS * 0.5;
|
||||
const float blurFalloff = 1.0 / (2.0 * blurSigma * blurSigma);
|
||||
|
||||
float ao = blurSample.x;
|
||||
float z = blurSample.y;
|
||||
|
||||
float deltaZ = (z - centerDepth) * BlurSharpness;
|
||||
float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ);
|
||||
|
||||
totalAO += w * ao;
|
||||
totalW += w;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 centerSample = textureOffset(AODepthTexture, TexCoord, ivec2( 0, 0)).xy;
|
||||
float centerDepth = centerSample.y;
|
||||
float totalAO = centerSample.x;
|
||||
float totalW = 1.0;
|
||||
|
||||
#if defined(BLUR_HORIZONTAL)
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-3, 0)).xy, 3.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-2, 0)).xy, 2.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-1, 0)).xy, 1.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 1, 0)).xy, 1.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 2, 0)).xy, 2.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 3, 0)).xy, 3.0, centerDepth, totalAO, totalW);
|
||||
#else
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -3)).xy, 3.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -2)).xy, 2.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -1)).xy, 1.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 1)).xy, 1.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 2)).xy, 2.0, centerDepth, totalAO, totalW);
|
||||
AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 3)).xy, 3.0, centerDepth, totalAO, totalW);
|
||||
#endif
|
||||
|
||||
float fragAO = totalAO / totalW;
|
||||
|
||||
#if defined(BLUR_HORIZONTAL)
|
||||
FragColor = vec4(fragAO, centerDepth, 0.0, 1.0);
|
||||
#else
|
||||
FragColor = vec4(pow(clamp(fragAO, 0.0, 1.0), PowExponent), 0.0, 0.0, 1.0);
|
||||
#endif
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
layout(binding=0) uniform sampler2D ExposureTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if __VERSION__ < 400
|
||||
ivec2 size = textureSize(ExposureTexture, 0);
|
||||
ivec2 tl = max(ivec2(TexCoord * vec2(size) - 0.5), ivec2(0));
|
||||
ivec2 br = min(tl + ivec2(1), size - ivec2(1));
|
||||
vec4 values = vec4(
|
||||
texelFetch(ExposureTexture, tl, 0).x,
|
||||
texelFetch(ExposureTexture, ivec2(tl.x, br.y), 0).x,
|
||||
texelFetch(ExposureTexture, ivec2(br.x, tl.y), 0).x,
|
||||
texelFetch(ExposureTexture, br, 0).x);
|
||||
#else
|
||||
vec4 values = textureGather(ExposureTexture, TexCoord);
|
||||
#endif
|
||||
|
||||
FragColor = vec4((values.x + values.y + values.z + values.w) * 0.25, 0.0, 0.0, 1.0);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D ExposureTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
float light = texture(ExposureTexture, TexCoord).x;
|
||||
float exposureAdjustment = 1.0 / max(ExposureBase + light * ExposureScale, ExposureMin);
|
||||
FragColor = vec4(exposureAdjustment, 0.0, 0.0, ExposureSpeed);
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D SceneTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(SceneTexture, Offset + TexCoord * Scale);
|
||||
FragColor = vec4(max(max(color.r, color.g), color.b), 0.0, 0.0, 1.0);
|
||||
}
|
|
@ -1,613 +0,0 @@
|
|||
//----------------------------------------------------------------------------------
|
||||
// File: es3-kepler\FXAA/FXAA3_11.h
|
||||
// SDK Version: v3.00
|
||||
// Email: gameworks@nvidia.com
|
||||
// Site: http://developer.nvidia.com/
|
||||
//
|
||||
// Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D InputTexture;
|
||||
|
||||
#ifdef FXAA_LUMA_PASS
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 tex = texture(InputTexture, TexCoord).rgb;
|
||||
vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
FragColor = vec4(tex, dot(tex, luma));
|
||||
}
|
||||
|
||||
#else // FXAA itself
|
||||
|
||||
//============================================================================
|
||||
// NVIDIA FXAA 3.11 by TIMOTHY LOTTES
|
||||
//============================================================================
|
||||
|
||||
#define FXAA_DISCARD 0
|
||||
|
||||
#define FXAA_GREEN_AS_LUMA 0
|
||||
|
||||
#define FxaaBool bool
|
||||
#define FxaaDiscard discard
|
||||
#define FxaaFloat float
|
||||
#define FxaaFloat2 vec2
|
||||
#define FxaaFloat3 vec3
|
||||
#define FxaaFloat4 vec4
|
||||
#define FxaaHalf float
|
||||
#define FxaaHalf2 vec2
|
||||
#define FxaaHalf3 vec3
|
||||
#define FxaaHalf4 vec4
|
||||
#define FxaaInt2 ivec2
|
||||
#define FxaaSat(x) clamp(x, 0.0, 1.0)
|
||||
#define FxaaTex sampler2D
|
||||
|
||||
#define FxaaTexTop(t, p) textureLod(t, p, 0.0)
|
||||
#define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o)
|
||||
|
||||
#if (FXAA_GATHER4_ALPHA == 1)
|
||||
#define FxaaTexAlpha4(t, p) textureGather(t, p, 3)
|
||||
#define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3)
|
||||
#define FxaaTexGreen4(t, p) textureGather(t, p, 1)
|
||||
#define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, p, o, 1)
|
||||
#endif
|
||||
|
||||
#if (FXAA_GREEN_AS_LUMA == 0)
|
||||
FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.w; }
|
||||
#else
|
||||
FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; }
|
||||
#endif
|
||||
|
||||
#if (FXAA_QUALITY__PRESET == 10)
|
||||
#define FXAA_QUALITY__PS 3
|
||||
#define FXAA_QUALITY__P0 1.5
|
||||
#define FXAA_QUALITY__P1 3.0
|
||||
#define FXAA_QUALITY__P2 12.0
|
||||
#elif (FXAA_QUALITY__PRESET == 11)
|
||||
#define FXAA_QUALITY__PS 4
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 3.0
|
||||
#define FXAA_QUALITY__P3 12.0
|
||||
#elif (FXAA_QUALITY__PRESET == 12)
|
||||
#define FXAA_QUALITY__PS 5
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 4.0
|
||||
#define FXAA_QUALITY__P4 12.0
|
||||
#elif (FXAA_QUALITY__PRESET == 13)
|
||||
#define FXAA_QUALITY__PS 6
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 4.0
|
||||
#define FXAA_QUALITY__P5 12.0
|
||||
#elif (FXAA_QUALITY__PRESET == 14)
|
||||
#define FXAA_QUALITY__PS 7
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 4.0
|
||||
#define FXAA_QUALITY__P6 12.0
|
||||
#elif (FXAA_QUALITY__PRESET == 15)
|
||||
#define FXAA_QUALITY__PS 8
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 2.0
|
||||
#define FXAA_QUALITY__P6 4.0
|
||||
#define FXAA_QUALITY__P7 12.0
|
||||
#elif (FXAA_QUALITY__PRESET == 20)
|
||||
#define FXAA_QUALITY__PS 3
|
||||
#define FXAA_QUALITY__P0 1.5
|
||||
#define FXAA_QUALITY__P1 2.0
|
||||
#define FXAA_QUALITY__P2 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 21)
|
||||
#define FXAA_QUALITY__PS 4
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 22)
|
||||
#define FXAA_QUALITY__PS 5
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 23)
|
||||
#define FXAA_QUALITY__PS 6
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 24)
|
||||
#define FXAA_QUALITY__PS 7
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 3.0
|
||||
#define FXAA_QUALITY__P6 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 25)
|
||||
#define FXAA_QUALITY__PS 8
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 2.0
|
||||
#define FXAA_QUALITY__P6 4.0
|
||||
#define FXAA_QUALITY__P7 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 26)
|
||||
#define FXAA_QUALITY__PS 9
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 2.0
|
||||
#define FXAA_QUALITY__P6 2.0
|
||||
#define FXAA_QUALITY__P7 4.0
|
||||
#define FXAA_QUALITY__P8 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 27)
|
||||
#define FXAA_QUALITY__PS 10
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 2.0
|
||||
#define FXAA_QUALITY__P6 2.0
|
||||
#define FXAA_QUALITY__P7 2.0
|
||||
#define FXAA_QUALITY__P8 4.0
|
||||
#define FXAA_QUALITY__P9 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 28)
|
||||
#define FXAA_QUALITY__PS 11
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 2.0
|
||||
#define FXAA_QUALITY__P6 2.0
|
||||
#define FXAA_QUALITY__P7 2.0
|
||||
#define FXAA_QUALITY__P8 2.0
|
||||
#define FXAA_QUALITY__P9 4.0
|
||||
#define FXAA_QUALITY__P10 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 29)
|
||||
#define FXAA_QUALITY__PS 12
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.5
|
||||
#define FXAA_QUALITY__P2 2.0
|
||||
#define FXAA_QUALITY__P3 2.0
|
||||
#define FXAA_QUALITY__P4 2.0
|
||||
#define FXAA_QUALITY__P5 2.0
|
||||
#define FXAA_QUALITY__P6 2.0
|
||||
#define FXAA_QUALITY__P7 2.0
|
||||
#define FXAA_QUALITY__P8 2.0
|
||||
#define FXAA_QUALITY__P9 2.0
|
||||
#define FXAA_QUALITY__P10 4.0
|
||||
#define FXAA_QUALITY__P11 8.0
|
||||
#elif (FXAA_QUALITY__PRESET == 39)
|
||||
#define FXAA_QUALITY__PS 12
|
||||
#define FXAA_QUALITY__P0 1.0
|
||||
#define FXAA_QUALITY__P1 1.0
|
||||
#define FXAA_QUALITY__P2 1.0
|
||||
#define FXAA_QUALITY__P3 1.0
|
||||
#define FXAA_QUALITY__P4 1.0
|
||||
#define FXAA_QUALITY__P5 1.5
|
||||
#define FXAA_QUALITY__P6 2.0
|
||||
#define FXAA_QUALITY__P7 2.0
|
||||
#define FXAA_QUALITY__P8 2.0
|
||||
#define FXAA_QUALITY__P9 2.0
|
||||
#define FXAA_QUALITY__P10 4.0
|
||||
#define FXAA_QUALITY__P11 8.0
|
||||
#endif
|
||||
|
||||
FxaaFloat4 FxaaPixelShader(FxaaFloat2 pos, FxaaTex tex, FxaaFloat2 fxaaQualityRcpFrame,
|
||||
FxaaFloat fxaaQualitySubpix, FxaaFloat fxaaQualityEdgeThreshold, FxaaFloat fxaaQualityEdgeThresholdMin)
|
||||
{
|
||||
FxaaFloat2 posM;
|
||||
posM.x = pos.x;
|
||||
posM.y = pos.y;
|
||||
#if (FXAA_GATHER4_ALPHA == 1)
|
||||
#if (FXAA_DISCARD == 0)
|
||||
FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);
|
||||
#if (FXAA_GREEN_AS_LUMA == 0)
|
||||
#define lumaM rgbyM.w
|
||||
#else
|
||||
#define lumaM rgbyM.y
|
||||
#endif
|
||||
#endif
|
||||
#if (FXAA_GREEN_AS_LUMA == 0)
|
||||
FxaaFloat4 luma4A = FxaaTexAlpha4(tex, posM);
|
||||
FxaaFloat4 luma4B = FxaaTexOffAlpha4(tex, posM, FxaaInt2(-1, -1));
|
||||
#else
|
||||
FxaaFloat4 luma4A = FxaaTexGreen4(tex, posM);
|
||||
FxaaFloat4 luma4B = FxaaTexOffGreen4(tex, posM, FxaaInt2(-1, -1));
|
||||
#endif
|
||||
#if (FXAA_DISCARD == 1)
|
||||
#define lumaM luma4A.w
|
||||
#endif
|
||||
#define lumaE luma4A.z
|
||||
#define lumaS luma4A.x
|
||||
#define lumaSE luma4A.y
|
||||
#define lumaNW luma4B.w
|
||||
#define lumaN luma4B.z
|
||||
#define lumaW luma4B.x
|
||||
#else
|
||||
FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);
|
||||
#if (FXAA_GREEN_AS_LUMA == 0)
|
||||
#define lumaM rgbyM.w
|
||||
#else
|
||||
#define lumaM rgbyM.y
|
||||
#endif
|
||||
FxaaFloat lumaS = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0, 1), fxaaQualityRcpFrame.xy));
|
||||
FxaaFloat lumaE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 0), fxaaQualityRcpFrame.xy));
|
||||
FxaaFloat lumaN = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0,-1), fxaaQualityRcpFrame.xy));
|
||||
FxaaFloat lumaW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 0), fxaaQualityRcpFrame.xy));
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat maxSM = max(lumaS, lumaM);
|
||||
FxaaFloat minSM = min(lumaS, lumaM);
|
||||
FxaaFloat maxESM = max(lumaE, maxSM);
|
||||
FxaaFloat minESM = min(lumaE, minSM);
|
||||
FxaaFloat maxWN = max(lumaN, lumaW);
|
||||
FxaaFloat minWN = min(lumaN, lumaW);
|
||||
FxaaFloat rangeMax = max(maxWN, maxESM);
|
||||
FxaaFloat rangeMin = min(minWN, minESM);
|
||||
FxaaFloat rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;
|
||||
FxaaFloat range = rangeMax - rangeMin;
|
||||
FxaaFloat rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);
|
||||
FxaaBool earlyExit = range < rangeMaxClamped;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
if(earlyExit)
|
||||
#if (FXAA_DISCARD == 1)
|
||||
FxaaDiscard;
|
||||
#else
|
||||
return rgbyM;
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_GATHER4_ALPHA == 0)
|
||||
FxaaFloat lumaNW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1,-1), fxaaQualityRcpFrame.xy));
|
||||
FxaaFloat lumaSE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 1), fxaaQualityRcpFrame.xy));
|
||||
FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1,-1), fxaaQualityRcpFrame.xy));
|
||||
FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));
|
||||
#else
|
||||
FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(1, -1), fxaaQualityRcpFrame.xy));
|
||||
FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat lumaNS = lumaN + lumaS;
|
||||
FxaaFloat lumaWE = lumaW + lumaE;
|
||||
FxaaFloat subpixRcpRange = 1.0/range;
|
||||
FxaaFloat subpixNSWE = lumaNS + lumaWE;
|
||||
FxaaFloat edgeHorz1 = (-2.0 * lumaM) + lumaNS;
|
||||
FxaaFloat edgeVert1 = (-2.0 * lumaM) + lumaWE;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat lumaNESE = lumaNE + lumaSE;
|
||||
FxaaFloat lumaNWNE = lumaNW + lumaNE;
|
||||
FxaaFloat edgeHorz2 = (-2.0 * lumaE) + lumaNESE;
|
||||
FxaaFloat edgeVert2 = (-2.0 * lumaN) + lumaNWNE;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat lumaNWSW = lumaNW + lumaSW;
|
||||
FxaaFloat lumaSWSE = lumaSW + lumaSE;
|
||||
FxaaFloat edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);
|
||||
FxaaFloat edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);
|
||||
FxaaFloat edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;
|
||||
FxaaFloat edgeVert3 = (-2.0 * lumaS) + lumaSWSE;
|
||||
FxaaFloat edgeHorz = abs(edgeHorz3) + edgeHorz4;
|
||||
FxaaFloat edgeVert = abs(edgeVert3) + edgeVert4;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat subpixNWSWNESE = lumaNWSW + lumaNESE;
|
||||
FxaaFloat lengthSign = fxaaQualityRcpFrame.x;
|
||||
FxaaBool horzSpan = edgeHorz >= edgeVert;
|
||||
FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
if(!horzSpan) lumaN = lumaW;
|
||||
if(!horzSpan) lumaS = lumaE;
|
||||
if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;
|
||||
FxaaFloat subpixB = (subpixA * (1.0/12.0)) - lumaM;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat gradientN = lumaN - lumaM;
|
||||
FxaaFloat gradientS = lumaS - lumaM;
|
||||
FxaaFloat lumaNN = lumaN + lumaM;
|
||||
FxaaFloat lumaSS = lumaS + lumaM;
|
||||
FxaaBool pairN = abs(gradientN) >= abs(gradientS);
|
||||
FxaaFloat gradient = max(abs(gradientN), abs(gradientS));
|
||||
if(pairN) lengthSign = -lengthSign;
|
||||
FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange);
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat2 posB;
|
||||
posB.x = posM.x;
|
||||
posB.y = posM.y;
|
||||
FxaaFloat2 offNP;
|
||||
offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;
|
||||
offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;
|
||||
if(!horzSpan) posB.x += lengthSign * 0.5;
|
||||
if( horzSpan) posB.y += lengthSign * 0.5;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat2 posN;
|
||||
posN.x = posB.x - offNP.x * FXAA_QUALITY__P0;
|
||||
posN.y = posB.y - offNP.y * FXAA_QUALITY__P0;
|
||||
FxaaFloat2 posP;
|
||||
posP.x = posB.x + offNP.x * FXAA_QUALITY__P0;
|
||||
posP.y = posB.y + offNP.y * FXAA_QUALITY__P0;
|
||||
FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0;
|
||||
FxaaFloat lumaEndN = FxaaLuma(FxaaTexTop(tex, posN));
|
||||
FxaaFloat subpixE = subpixC * subpixC;
|
||||
FxaaFloat lumaEndP = FxaaLuma(FxaaTexTop(tex, posP));
|
||||
/*--------------------------------------------------------------------------*/
|
||||
if(!pairN) lumaNN = lumaSS;
|
||||
FxaaFloat gradientScaled = gradient * 1.0/4.0;
|
||||
FxaaFloat lumaMM = lumaM - lumaNN * 0.5;
|
||||
FxaaFloat subpixF = subpixD * subpixE;
|
||||
FxaaBool lumaMLTZero = lumaMM < 0.0;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
lumaEndN -= lumaNN * 0.5;
|
||||
lumaEndP -= lumaNN * 0.5;
|
||||
FxaaBool doneN = abs(lumaEndN) >= gradientScaled;
|
||||
FxaaBool doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P1;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P1;
|
||||
FxaaBool doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P1;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P1;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P2;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P2;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P2;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P2;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 3)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P3;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P3;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P3;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P3;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 4)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P4;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P4;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P4;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P4;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 5)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P5;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P5;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P5;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P5;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 6)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P6;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P6;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P6;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P6;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 7)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P7;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P7;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P7;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P7;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 8)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P8;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P8;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P8;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P8;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 9)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P9;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P9;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P9;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P9;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 10)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P10;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P10;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P10;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P10;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 11)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P11;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P11;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P11;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P11;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if (FXAA_QUALITY__PS > 12)
|
||||
if(doneNP) {
|
||||
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
||||
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
||||
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
||||
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
||||
doneN = abs(lumaEndN) >= gradientScaled;
|
||||
doneP = abs(lumaEndP) >= gradientScaled;
|
||||
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P12;
|
||||
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P12;
|
||||
doneNP = (!doneN) || (!doneP);
|
||||
if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P12;
|
||||
if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P12;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat dstN = posM.x - posN.x;
|
||||
FxaaFloat dstP = posP.x - posM.x;
|
||||
if(!horzSpan) dstN = posM.y - posN.y;
|
||||
if(!horzSpan) dstP = posP.y - posM.y;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;
|
||||
FxaaFloat spanLength = (dstP + dstN);
|
||||
FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;
|
||||
FxaaFloat spanLengthRcp = 1.0/spanLength;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaBool directionN = dstN < dstP;
|
||||
FxaaFloat dst = min(dstN, dstP);
|
||||
FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP;
|
||||
FxaaFloat subpixG = subpixF * subpixF;
|
||||
FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5;
|
||||
FxaaFloat subpixH = subpixG * fxaaQualitySubpix;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0;
|
||||
FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH);
|
||||
if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;
|
||||
if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;
|
||||
#if (FXAA_DISCARD == 1)
|
||||
return FxaaTexTop(tex, posM);
|
||||
#else
|
||||
return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM);
|
||||
#endif
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = FxaaPixelShader(TexCoord, InputTexture, ReciprocalResolution, 0.75f, 0.166f, 0.0833f);
|
||||
}
|
||||
|
||||
#endif // FXAA_LUMA_PASS
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
Original Lens Distortion Algorithm from SSontech
|
||||
http://www.ssontech.com/content/lensalg.htm
|
||||
|
||||
If (u,v) are the coordinates of a feature in the undistorted perfect
|
||||
image plane, then (u', v') are the coordinates of the feature on the
|
||||
distorted image plate, ie the scanned or captured image from the
|
||||
camera. The distortion occurs radially away from the image center,
|
||||
with correction for the image aspect ratio (image_aspect = physical
|
||||
image width/height), as follows:
|
||||
|
||||
r2 = image_aspect*image_aspect*u*u + v*v
|
||||
f = 1 + r2*(k + kcube*sqrt(r2))
|
||||
u' = f*u
|
||||
v' = f*v
|
||||
|
||||
The constant k is the distortion coefficient that appears on the lens
|
||||
panel and through Sizzle. It is generally a small positive or negative
|
||||
number under 1%. The constant kcube is the cubic distortion value found
|
||||
on the image preprocessor's lens panel: it can be used to undistort or
|
||||
redistort images, but it does not affect or get computed by the solver.
|
||||
When no cubic distortion is needed, neither is the square root, saving
|
||||
time.
|
||||
|
||||
Chromatic Aberration example,
|
||||
using red distord channel with green and blue undistord channel:
|
||||
|
||||
k = vec3(-0.15, 0.0, 0.0);
|
||||
kcube = vec3(0.15, 0.0, 0.0);
|
||||
*/
|
||||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D InputTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 position = (TexCoord - vec2(0.5));
|
||||
|
||||
vec2 p = vec2(position.x * Aspect, position.y);
|
||||
float r2 = dot(p, p);
|
||||
vec3 f = vec3(1.0) + r2 * (k.rgb + kcube.rgb * sqrt(r2));
|
||||
|
||||
vec3 x = f * position.x * Scale + 0.5;
|
||||
vec3 y = f * position.y * Scale + 0.5;
|
||||
|
||||
vec3 c;
|
||||
c.r = texture(InputTexture, vec2(x.r, y.r)).r;
|
||||
c.g = texture(InputTexture, vec2(x.g, y.g)).g;
|
||||
c.b = texture(InputTexture, vec2(x.b, y.b)).b;
|
||||
|
||||
FragColor = vec4(c, 1.0);
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
#if defined(MULTISAMPLE)
|
||||
layout(binding=0) uniform sampler2DMS DepthTexture;
|
||||
layout(binding=1) uniform sampler2DMS ColorTexture;
|
||||
#else
|
||||
layout(binding=0) uniform sampler2D DepthTexture;
|
||||
layout(binding=1) uniform sampler2D ColorTexture;
|
||||
#endif
|
||||
|
||||
float normalizeDepth(float depth)
|
||||
{
|
||||
float normalizedDepth = clamp(InverseDepthRangeA * depth + InverseDepthRangeB, 0.0, 1.0);
|
||||
return 1.0 / (normalizedDepth * LinearizeDepthA + LinearizeDepthB);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 uv = Offset + TexCoord * Scale;
|
||||
|
||||
#if defined(MULTISAMPLE)
|
||||
ivec2 texSize = textureSize(DepthTexture);
|
||||
#else
|
||||
ivec2 texSize = textureSize(DepthTexture, 0);
|
||||
#endif
|
||||
|
||||
ivec2 ipos = ivec2(max(uv * vec2(texSize), vec2(0.0)));
|
||||
|
||||
#if defined(MULTISAMPLE)
|
||||
float depth = normalizeDepth(texelFetch(ColorTexture, ipos, SampleIndex).a != 0.0 ? texelFetch(DepthTexture, ipos, SampleIndex).x : 1.0);
|
||||
#else
|
||||
float depth = normalizeDepth(texelFetch(ColorTexture, ipos, 0).a != 0.0 ? texelFetch(DepthTexture, ipos, 0).x : 1.0);
|
||||
#endif
|
||||
|
||||
FragColor = vec4(depth, 0.0, 0.0, 1.0);
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D LeftEyeTexture;
|
||||
layout(binding=1) uniform sampler2D RightEyeTexture;
|
||||
|
||||
vec4 ApplyGamma(vec4 c)
|
||||
{
|
||||
vec3 val = c.rgb * Contrast - (Contrast - 1.0) * 0.5;
|
||||
val += Brightness * 0.5;
|
||||
val = pow(max(val, vec3(0.0)), vec3(InvGamma));
|
||||
return vec4(val, c.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
int thisVerticalPixel = int(gl_FragCoord.y); // Bottom row is typically the right eye, when WindowHeight is even
|
||||
int thisHorizontalPixel = int(gl_FragCoord.x); // column
|
||||
bool isLeftEye = (thisVerticalPixel // because we want to alternate eye view on each row
|
||||
+ thisHorizontalPixel // and each column
|
||||
+ WindowPositionParity // because the window might not be aligned to the screen
|
||||
) % 2 == 0;
|
||||
vec4 inputColor;
|
||||
if (isLeftEye) {
|
||||
inputColor = texture(LeftEyeTexture, UVOffset + TexCoord * UVScale);
|
||||
}
|
||||
else {
|
||||
// inputColor = vec4(0, 1, 0, 1);
|
||||
inputColor = texture(RightEyeTexture, UVOffset + TexCoord * UVScale);
|
||||
}
|
||||
FragColor = ApplyGamma(inputColor);
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D LeftEyeTexture;
|
||||
layout(binding=1) uniform sampler2D RightEyeTexture;
|
||||
|
||||
vec4 ApplyGamma(vec4 c)
|
||||
{
|
||||
vec3 val = c.rgb * Contrast - (Contrast - 1.0) * 0.5;
|
||||
val += Brightness * 0.5;
|
||||
val = pow(max(val, vec3(0.0)), vec3(InvGamma));
|
||||
return vec4(val, c.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
int thisHorizontalPixel = int(gl_FragCoord.x); // zero-based column index from left
|
||||
bool isLeftEye = (thisHorizontalPixel // because we want to alternate eye view on each column
|
||||
+ WindowPositionParity // because the window might not be aligned to the screen
|
||||
) % 2 == 0;
|
||||
vec4 inputColor;
|
||||
if (isLeftEye) {
|
||||
inputColor = texture(LeftEyeTexture, UVOffset + TexCoord * UVScale);
|
||||
}
|
||||
else {
|
||||
// inputColor = vec4(0, 1, 0, 1);
|
||||
inputColor = texture(RightEyeTexture, UVOffset + TexCoord * UVScale);
|
||||
}
|
||||
FragColor = ApplyGamma(inputColor);
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D LeftEyeTexture;
|
||||
layout(binding=1) uniform sampler2D RightEyeTexture;
|
||||
|
||||
vec4 ApplyGamma(vec4 c)
|
||||
{
|
||||
vec3 val = c.rgb * Contrast - (Contrast - 1.0) * 0.5;
|
||||
val += Brightness * 0.5;
|
||||
val = pow(max(val, vec3(0.0)), vec3(InvGamma));
|
||||
return vec4(val, c.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
int thisVerticalPixel = int(gl_FragCoord.y); // Bottom row is typically the right eye, when WindowHeight is even
|
||||
bool isLeftEye = (thisVerticalPixel // because we want to alternate eye view on each row
|
||||
+ WindowPositionParity // because the window might not be aligned to the screen
|
||||
) % 2 == 0;
|
||||
vec4 inputColor;
|
||||
if (isLeftEye) {
|
||||
inputColor = texture(LeftEyeTexture, UVOffset + TexCoord * UVScale);
|
||||
}
|
||||
else {
|
||||
// inputColor = vec4(0, 1, 0, 1);
|
||||
inputColor = texture(RightEyeTexture, UVOffset + TexCoord * UVScale);
|
||||
}
|
||||
FragColor = ApplyGamma(inputColor);
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
// A node in an AABB binary tree with lines stored in the leaf nodes
|
||||
struct GPUNode
|
||||
{
|
||||
vec2 aabb_min; // Min xy values for the axis-aligned box containing the node and its subtree
|
||||
vec2 aabb_max; // Max xy values
|
||||
int left; // Left subnode index
|
||||
int right; // Right subnode index
|
||||
int line_index; // Line index if it is a leaf node, otherwise -1
|
||||
int padding; // Unused - maintains 16 byte alignment
|
||||
};
|
||||
|
||||
// 2D line segment, referenced by leaf nodes
|
||||
struct GPULine
|
||||
{
|
||||
vec2 pos; // Line start position
|
||||
vec2 delta; // Line end position - line start position
|
||||
};
|
||||
|
||||
layout(std430, binding = 4) buffer LightNodes
|
||||
{
|
||||
GPUNode nodes[];
|
||||
};
|
||||
|
||||
layout(std430, binding = 5) buffer LightLines
|
||||
{
|
||||
GPULine lines[];
|
||||
};
|
||||
|
||||
layout(std430, binding = 6) buffer LightList
|
||||
{
|
||||
vec4 lights[];
|
||||
};
|
||||
|
||||
// Overlap test between line segment and axis-aligned bounding box. Returns true if they overlap.
|
||||
bool overlapRayAABB(vec2 ray_start2d, vec2 ray_end2d, vec2 aabb_min2d, vec2 aabb_max2d)
|
||||
{
|
||||
// To do: simplify test to use a 2D test
|
||||
vec3 ray_start = vec3(ray_start2d, 0.0);
|
||||
vec3 ray_end = vec3(ray_end2d, 0.0);
|
||||
vec3 aabb_min = vec3(aabb_min2d, -1.0);
|
||||
vec3 aabb_max = vec3(aabb_max2d, 1.0);
|
||||
|
||||
vec3 c = (ray_start + ray_end) * 0.5f;
|
||||
vec3 w = ray_end - c;
|
||||
vec3 h = (aabb_max - aabb_min) * 0.5f; // aabb.extents();
|
||||
|
||||
c -= (aabb_max + aabb_min) * 0.5f; // aabb.center();
|
||||
|
||||
vec3 v = abs(w);
|
||||
|
||||
if (abs(c.x) > v.x + h.x || abs(c.y) > v.y + h.y || abs(c.z) > v.z + h.z)
|
||||
return false; // disjoint;
|
||||
|
||||
if (abs(c.y * w.z - c.z * w.y) > h.y * v.z + h.z * v.y ||
|
||||
abs(c.x * w.z - c.z * w.x) > h.x * v.z + h.z * v.x ||
|
||||
abs(c.x * w.y - c.y * w.x) > h.x * v.y + h.y * v.x)
|
||||
return false; // disjoint;
|
||||
|
||||
return true; // overlap;
|
||||
}
|
||||
|
||||
// Intersection test between two line segments.
|
||||
// Returns the intersection point as a value between 0-1 on the ray line segment. 1.0 if there was no hit.
|
||||
float intersectRayLine(vec2 ray_start, vec2 ray_end, int line_index, vec2 raydelta, float rayd, float raydist2)
|
||||
{
|
||||
const float epsilon = 0.0000001;
|
||||
GPULine line = lines[line_index];
|
||||
|
||||
vec2 raynormal = vec2(raydelta.y, -raydelta.x);
|
||||
|
||||
float den = dot(raynormal, line.delta);
|
||||
if (abs(den) > epsilon)
|
||||
{
|
||||
float t_line = (rayd - dot(raynormal, line.pos)) / den;
|
||||
if (t_line >= 0.0 && t_line <= 1.0)
|
||||
{
|
||||
vec2 linehitdelta = line.pos + line.delta * t_line - ray_start;
|
||||
float t = dot(raydelta, linehitdelta) / raydist2;
|
||||
return t > 0.0 ? t : 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
// Returns true if an AABB tree node is a leaf node. Leaf nodes contains a line.
|
||||
bool isLeaf(int node_index)
|
||||
{
|
||||
return nodes[node_index].line_index != -1;
|
||||
}
|
||||
|
||||
// Perform ray intersection test between the ray line segment and all the lines in the AABB binary tree.
|
||||
// Returns the intersection point as a value between 0-1 on the ray line segment. 1.0 if there was no hit.
|
||||
float rayTest(vec2 ray_start, vec2 ray_end)
|
||||
{
|
||||
vec2 raydelta = ray_end - ray_start;
|
||||
float raydist2 = dot(raydelta, raydelta);
|
||||
vec2 raynormal = vec2(raydelta.y, -raydelta.x);
|
||||
float rayd = dot(raynormal, ray_start);
|
||||
if (raydist2 < 1.0)
|
||||
return 1.0;
|
||||
|
||||
float t = 1.0;
|
||||
|
||||
// Walk the AABB binary tree searching for nodes touching the ray line segment's AABB box.
|
||||
// When it reaches a leaf node, use a line segment intersection test to see if we got a hit.
|
||||
|
||||
int stack[32];
|
||||
int stack_pos = 1;
|
||||
stack[0] = NodesCount - 1;
|
||||
while (stack_pos > 0)
|
||||
{
|
||||
int node_index = stack[stack_pos - 1];
|
||||
|
||||
if (!overlapRayAABB(ray_start, ray_end, nodes[node_index].aabb_min, nodes[node_index].aabb_max))
|
||||
{
|
||||
stack_pos--;
|
||||
}
|
||||
else if (isLeaf(node_index))
|
||||
{
|
||||
t = min(intersectRayLine(ray_start, ray_end, nodes[node_index].line_index, raydelta, rayd, raydist2), t);
|
||||
stack_pos--;
|
||||
}
|
||||
else if (stack_pos == 32)
|
||||
{
|
||||
stack_pos--; // stack overflow
|
||||
}
|
||||
else
|
||||
{
|
||||
stack[stack_pos - 1] = nodes[node_index].left;
|
||||
stack[stack_pos] = nodes[node_index].right;
|
||||
stack_pos++;
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Find the light that belongs to this texel in the shadowmap texture we output to:
|
||||
|
||||
int lightIndex = int(gl_FragCoord.y);
|
||||
|
||||
vec4 light = lights[lightIndex];
|
||||
float radius = light.w;
|
||||
vec2 lightpos = light.xy;
|
||||
|
||||
if (radius > 0.0)
|
||||
{
|
||||
// We found an active light. Calculate the ray direction for the texel.
|
||||
//
|
||||
// The texels are laid out so that there are four projections:
|
||||
//
|
||||
// * top-left to top-right
|
||||
// * top-right to bottom-right
|
||||
// * bottom-right to bottom-left
|
||||
// * bottom-left to top-left
|
||||
//
|
||||
vec2 raydir;
|
||||
float u = gl_FragCoord.x / ShadowmapQuality * 4.0;
|
||||
switch (int(u))
|
||||
{
|
||||
case 0: raydir = vec2(u * 2.0 - 1.0, 1.0); break;
|
||||
case 1: raydir = vec2(1.0, 1.0 - (u - 1.0) * 2.0); break;
|
||||
case 2: raydir = vec2(1.0 - (u - 2.0) * 2.0, -1.0); break;
|
||||
case 3: raydir = vec2(-1.0, (u - 3.0) * 2.0 - 1.0); break;
|
||||
}
|
||||
|
||||
// Find the position for the ray starting at the light position and travelling until light contribution is zero:
|
||||
vec2 pixelpos = lightpos + raydir * radius;
|
||||
|
||||
// Check if we hit any line between the light and the end position:
|
||||
float t = rayTest(lightpos, pixelpos);
|
||||
|
||||
// Calculate the square distance for the hit, if any:
|
||||
vec2 delta = (pixelpos - lightpos) * t;
|
||||
float dist2 = dot(delta, delta);
|
||||
|
||||
FragColor = vec4(dist2, 0.0, 0.0, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D DepthTexture;
|
||||
|
||||
#if defined(MULTISAMPLE)
|
||||
layout(binding=1) uniform sampler2DMS NormalTexture;
|
||||
#else
|
||||
layout(binding=1) uniform sampler2D NormalTexture;
|
||||
#endif
|
||||
|
||||
#if defined(USE_RANDOM_TEXTURE)
|
||||
layout(binding=2) uniform sampler2D RandomTexture;
|
||||
#endif
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
// Calculate eye space position for the specified texture coordinate
|
||||
vec3 FetchViewPos(vec2 uv)
|
||||
{
|
||||
float z = texture(DepthTexture, uv).x;
|
||||
return vec3((UVToViewA * uv + UVToViewB) * z, z);
|
||||
}
|
||||
|
||||
#if defined(MULTISAMPLE)
|
||||
vec3 SampleNormal(vec2 uv)
|
||||
{
|
||||
ivec2 texSize = textureSize(NormalTexture);
|
||||
ivec2 ipos = ivec2(uv * vec2(texSize));
|
||||
return texelFetch(NormalTexture, ipos, SampleIndex).xyz * 2.0 - 1.0;
|
||||
}
|
||||
#else
|
||||
vec3 SampleNormal(vec2 uv)
|
||||
{
|
||||
ivec2 texSize = textureSize(NormalTexture, 0);
|
||||
ivec2 ipos = ivec2(uv * vec2(texSize));
|
||||
return texelFetch(NormalTexture, ipos, 0).xyz * 2.0 - 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Look up the eye space normal for the specified texture coordinate
|
||||
vec3 FetchNormal(vec2 uv)
|
||||
{
|
||||
vec3 normal = SampleNormal(Offset + uv * Scale);
|
||||
if (length(normal) > 0.1)
|
||||
{
|
||||
normal = normalize(normal);
|
||||
normal.z = -normal.z;
|
||||
return normal;
|
||||
}
|
||||
else
|
||||
{
|
||||
return vec3(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Compute normalized 2D direction
|
||||
vec2 RotateDirection(vec2 dir, vec2 cossin)
|
||||
{
|
||||
return vec2(dir.x * cossin.x - dir.y * cossin.y, dir.x * cossin.y + dir.y * cossin.x);
|
||||
}
|
||||
|
||||
vec4 GetJitter()
|
||||
{
|
||||
#if !defined(USE_RANDOM_TEXTURE)
|
||||
return vec4(1,0,1,1);
|
||||
//vec3 rand = noise3(TexCoord.x + TexCoord.y);
|
||||
//float angle = 2.0 * PI * rand.x / NUM_DIRECTIONS;
|
||||
//return vec4(cos(angle), sin(angle), rand.y, rand.z);
|
||||
#else
|
||||
return texture(RandomTexture, gl_FragCoord.xy / RANDOM_TEXTURE_WIDTH);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Calculates the ambient occlusion of a sample
|
||||
float ComputeSampleAO(vec3 kernelPos, vec3 normal, vec3 samplePos)
|
||||
{
|
||||
vec3 v = samplePos - kernelPos;
|
||||
float distanceSquare = dot(v, v);
|
||||
float nDotV = dot(normal, v) * inversesqrt(distanceSquare);
|
||||
return clamp(nDotV - NDotVBias, 0.0, 1.0) * clamp(distanceSquare * NegInvR2 + 1.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
// Calculates the total ambient occlusion for the entire fragment
|
||||
float ComputeAO(vec3 viewPosition, vec3 viewNormal)
|
||||
{
|
||||
vec4 rand = GetJitter();
|
||||
|
||||
float radiusPixels = RadiusToScreen / viewPosition.z;
|
||||
float stepSizePixels = radiusPixels / (NUM_STEPS + 1.0);
|
||||
|
||||
const float directionAngleStep = 2.0 * PI / NUM_DIRECTIONS;
|
||||
float ao = 0.0;
|
||||
|
||||
for (float directionIndex = 0.0; directionIndex < NUM_DIRECTIONS; ++directionIndex)
|
||||
{
|
||||
float angle = directionAngleStep * directionIndex;
|
||||
|
||||
vec2 direction = RotateDirection(vec2(cos(angle), sin(angle)), rand.xy);
|
||||
float rayPixels = (rand.z * stepSizePixels + 1.0);
|
||||
|
||||
for (float StepIndex = 0.0; StepIndex < NUM_STEPS; ++StepIndex)
|
||||
{
|
||||
vec2 sampleUV = round(rayPixels * direction) * InvFullResolution + TexCoord;
|
||||
vec3 samplePos = FetchViewPos(sampleUV);
|
||||
ao += ComputeSampleAO(viewPosition, viewNormal, samplePos);
|
||||
rayPixels += stepSizePixels;
|
||||
}
|
||||
}
|
||||
|
||||
ao *= AOMultiplier / (NUM_DIRECTIONS * NUM_STEPS);
|
||||
return clamp(1.0 - ao * 2.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 viewPosition = FetchViewPos(TexCoord);
|
||||
vec3 viewNormal = FetchNormal(TexCoord);
|
||||
float occlusion = viewNormal != vec3(0.0) ? ComputeAO(viewPosition, viewNormal) * AOStrength + (1.0 - AOStrength) : 1.0;
|
||||
|
||||
FragColor = vec4(occlusion, viewPosition.z, 0.0, 1.0);
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D AODepthTexture;
|
||||
|
||||
#if defined(MULTISAMPLE)
|
||||
layout(binding=1) uniform sampler2DMS SceneFogTexture;
|
||||
#else
|
||||
layout(binding=1) uniform sampler2D SceneFogTexture;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 uv = Offset + TexCoord * Scale;
|
||||
|
||||
#if defined(MULTISAMPLE)
|
||||
ivec2 texSize = textureSize(SceneFogTexture);
|
||||
#else
|
||||
ivec2 texSize = textureSize(SceneFogTexture, 0);
|
||||
#endif
|
||||
ivec2 ipos = ivec2(uv * vec2(texSize));
|
||||
|
||||
#if defined(MULTISAMPLE)
|
||||
vec3 fogColor = texelFetch(SceneFogTexture, ipos, 0).rgb;
|
||||
#else
|
||||
vec3 fogColor = texelFetch(SceneFogTexture, ipos, 0).rgb;
|
||||
#endif
|
||||
|
||||
vec4 ssao = texture(AODepthTexture, TexCoord);
|
||||
float attenutation = ssao.x;
|
||||
|
||||
if (DebugMode == 0)
|
||||
FragColor = vec4(fogColor, 1.0 - attenutation);
|
||||
else if (DebugMode < 3)
|
||||
FragColor = vec4(attenutation, attenutation, attenutation, 1.0);
|
||||
else if (DebugMode == 3)
|
||||
FragColor = vec4(ssao.yyy / 1000.0, 1.0);
|
||||
else
|
||||
FragColor = vec4(ssao.xyz, 1.0);
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
|
||||
layout(location=0) in vec2 TexCoord;
|
||||
layout(location=0) out vec4 FragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D InputTexture;
|
||||
|
||||
vec3 Linear(vec3 c)
|
||||
{
|
||||
//c = max(c, vec3(0.0));
|
||||
//return pow(c, 2.2);
|
||||
return c * c; // cheaper, but assuming gamma of 2.0 instead of 2.2
|
||||
}
|
||||
|
||||
vec3 sRGB(vec3 c)
|
||||
{
|
||||
c = max(c, vec3(0.0));
|
||||
//return pow(c, vec3(1.0 / 2.2));
|
||||
return sqrt(c); // cheaper, but assuming gamma of 2.0 instead of 2.2
|
||||
}
|
||||
|
||||
#if defined(LINEAR)
|
||||
|
||||
vec3 Tonemap(vec3 color)
|
||||
{
|
||||
return sRGB(color);
|
||||
}
|
||||
|
||||
#elif defined(REINHARD)
|
||||
|
||||
vec3 Tonemap(vec3 color)
|
||||
{
|
||||
color = color / (1.0 + color);
|
||||
return sRGB(color);
|
||||
}
|
||||
|
||||
#elif defined(HEJLDAWSON)
|
||||
|
||||
vec3 Tonemap(vec3 color)
|
||||
{
|
||||
vec3 x = max(vec3(0.0), color - 0.004);
|
||||
return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); // no sRGB needed
|
||||
}
|
||||
|
||||
#elif defined(UNCHARTED2)
|
||||
|
||||
vec3 Uncharted2Tonemap(vec3 x)
|
||||
{
|
||||
float A = 0.15;
|
||||
float B = 0.50;
|
||||
float C = 0.10;
|
||||
float D = 0.20;
|
||||
float E = 0.02;
|
||||
float F = 0.30;
|
||||
return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
|
||||
}
|
||||
|
||||
vec3 Tonemap(vec3 color)
|
||||
{
|
||||
float W = 11.2;
|
||||
vec3 curr = Uncharted2Tonemap(color);
|
||||
vec3 whiteScale = vec3(1) / Uncharted2Tonemap(vec3(W));
|
||||
return sRGB(curr * whiteScale);
|
||||
}
|
||||
|
||||
#elif defined(PALETTE)
|
||||
|
||||
layout(binding=1) uniform sampler2D PaletteLUT;
|
||||
|
||||
vec3 Tonemap(vec3 color)
|
||||
{
|
||||
ivec3 c = ivec3(clamp(color.rgb, vec3(0.0), vec3(1.0)) * 63.0 + 0.5);
|
||||
int index = (c.r * 64 + c.g) * 64 + c.b;
|
||||
int tx = index % 512;
|
||||
int ty = index / 512;
|
||||
return texelFetch(PaletteLUT, ivec2(tx, ty), 0).rgb;
|
||||
}
|
||||
|
||||
#else
|
||||
#error Tonemap mode define is missing
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture(InputTexture, TexCoord).rgb;
|
||||
#ifndef PALETTE
|
||||
color = Linear(color); // needed because gzdoom's scene texture is not linear at the moment
|
||||
#endif
|
||||
FragColor = vec4(Tonemap(color), 1.0);
|
||||
}
|
Loading…
Reference in a new issue