diff --git a/wadsrc/static/shaders_gles/glsl/material_pbr.fp b/wadsrc/static/shaders_gles/glsl/material_pbr.fp deleted file mode 100644 index 6859c28bb..000000000 --- a/wadsrc/static/shaders_gles/glsl/material_pbr.fp +++ /dev/null @@ -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 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 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)); -} diff --git a/wadsrc/static/shaders_gles/glsl/material_specular.fp b/wadsrc/static/shaders_gles/glsl/material_specular.fp deleted file mode 100644 index f6c142308..000000000 --- a/wadsrc/static/shaders_gles/glsl/material_specular.fp +++ /dev/null @@ -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= 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= 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 diff --git a/wadsrc/static/shaders_gles/pp/lensdistortion.fp b/wadsrc/static/shaders_gles/pp/lensdistortion.fp deleted file mode 100644 index 1b0d47b4f..000000000 --- a/wadsrc/static/shaders_gles/pp/lensdistortion.fp +++ /dev/null @@ -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); -} diff --git a/wadsrc/static/shaders_gles/pp/lineardepth.fp b/wadsrc/static/shaders_gles/pp/lineardepth.fp deleted file mode 100644 index 7966e310a..000000000 --- a/wadsrc/static/shaders_gles/pp/lineardepth.fp +++ /dev/null @@ -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); -} diff --git a/wadsrc/static/shaders_gles/pp/present_checker3d.fp b/wadsrc/static/shaders_gles/pp/present_checker3d.fp deleted file mode 100644 index 36d77e250..000000000 --- a/wadsrc/static/shaders_gles/pp/present_checker3d.fp +++ /dev/null @@ -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); -} diff --git a/wadsrc/static/shaders_gles/pp/present_column3d.fp b/wadsrc/static/shaders_gles/pp/present_column3d.fp deleted file mode 100644 index cf8758e3a..000000000 --- a/wadsrc/static/shaders_gles/pp/present_column3d.fp +++ /dev/null @@ -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); -} diff --git a/wadsrc/static/shaders_gles/pp/present_row3d.fp b/wadsrc/static/shaders_gles/pp/present_row3d.fp deleted file mode 100644 index a88be0ed0..000000000 --- a/wadsrc/static/shaders_gles/pp/present_row3d.fp +++ /dev/null @@ -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); -} diff --git a/wadsrc/static/shaders_gles/pp/shadowmap.fp b/wadsrc/static/shaders_gles/pp/shadowmap.fp deleted file mode 100644 index ec141f0fc..000000000 --- a/wadsrc/static/shaders_gles/pp/shadowmap.fp +++ /dev/null @@ -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); - } -} diff --git a/wadsrc/static/shaders_gles/pp/ssao.fp b/wadsrc/static/shaders_gles/pp/ssao.fp deleted file mode 100644 index b3ab1178c..000000000 --- a/wadsrc/static/shaders_gles/pp/ssao.fp +++ /dev/null @@ -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); -} diff --git a/wadsrc/static/shaders_gles/pp/ssaocombine.fp b/wadsrc/static/shaders_gles/pp/ssaocombine.fp deleted file mode 100644 index 0d592549f..000000000 --- a/wadsrc/static/shaders_gles/pp/ssaocombine.fp +++ /dev/null @@ -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); -} diff --git a/wadsrc/static/shaders_gles/pp/tonemap.fp b/wadsrc/static/shaders_gles/pp/tonemap.fp deleted file mode 100644 index f18e9fc9e..000000000 --- a/wadsrc/static/shaders_gles/pp/tonemap.fp +++ /dev/null @@ -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); -}