more branching removal

This commit is contained in:
SamGondelman 2018-10-25 14:29:14 -07:00
parent e8c5324e39
commit dc9405775f
64 changed files with 356 additions and 538 deletions

View file

@ -14,8 +14,6 @@ void main(void) {
ivec2 texCoord = ivec2(floor(varTexCoord0 * vec2(textureData.textureSize)));
texCoord.x /= 2;
int row = int(floor(gl_FragCoord.y));
if (row % 2 > 0) {
texCoord.x += (textureData.textureSize.x / 2);
}
texCoord.x += int(row % 2 > 0) * (textureData.textureSize.x / 2);
outFragColor = vec4(pow(texelFetch(colorMap, texCoord, 0).rgb, vec3(2.2)), 1.0);
}

View file

@ -9,7 +9,7 @@ layout(location=0) out vec4 outFragColor;
float sRGBFloatToLinear(float value) {
const float SRGB_ELBOW = 0.04045;
return (value <= SRGB_ELBOW) ? value / 12.92 : pow((value + 0.055) / 1.055, 2.4);
return mix(pow((value + 0.055) / 1.055, 2.4), value / 12.92, float(value <= SRGB_ELBOW));
}
vec3 colorToLinearRGB(vec3 srgb) {

View file

@ -80,10 +80,11 @@ float interpolate3Points(float y1, float y2, float y3, float u) {
halfSlope = (y3 - y1) / 2.0f;
float slope12 = y2 - y1;
float slope23 = y3 - y2;
if (abs(halfSlope) > abs(slope12)) {
halfSlope = slope12;
} else if (abs(halfSlope) > abs(slope23)) {
halfSlope = slope23;
{
float check = float(abs(halfSlope) > abs(slope12));
halfSlope = mix(halfSlope, slope12, check);
halfSlope = mix(halfSlope, slope23, (1.0 - check) * float(abs(halfSlope) > abs(slope23)));
}
}

View file

@ -151,37 +151,29 @@ float fetchScatteringMap(vec2 uv) {
<@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, scattering)@>
float check;
<@if albedo@>
check = float((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0);
vec4 <$albedo$> = check * fetchAlbedoMap(<$texcoord0$>) + vec4(1.0 - check);
vec4 <$albedo$> = mix(vec4(1.0), fetchAlbedoMap(<$texcoord0$>), float((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0));
<@endif@>
<@if roughness@>
check = float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0);
float <$roughness$> = check * fetchRoughnessMap(<$texcoord0$>) + (1.0 - check);
float <$roughness$> = mix(1.0, fetchRoughnessMap(<$texcoord0$>), float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0));
<@endif@>
<@if normal@>
check = float((<$matKey$> & NORMAL_MAP_BIT) != 0);
vec3 <$normal$> = check * fetchNormalMap(<$texcoord0$>) + vec3(0.0, 1.0 - check, 0.0);
vec3 <$normal$> = mix(vec3(0.0, 1.0, 0.0), fetchNormalMap(<$texcoord0$>), float((<$matKey$> & NORMAL_MAP_BIT) != 0));
<@endif@>
<@if metallic@>
check = float((<$matKey$> & METALLIC_MAP_BIT) != 0);
float <$metallic$> = check * fetchMetallicMap(<$texcoord0$>);
float <$metallic$> = float((<$matKey$> & METALLIC_MAP_BIT) != 0) * fetchMetallicMap(<$texcoord0$>);
<@endif@>
<@if emissive@>
check = float((<$matKey$> & EMISSIVE_MAP_BIT) != 0);
vec3 <$emissive$> = check * fetchEmissiveMap(<$texcoord0$>);
vec3 <$emissive$> = float((<$matKey$> & EMISSIVE_MAP_BIT) != 0) * fetchEmissiveMap(<$texcoord0$>);
<@endif@>
<@if scattering@>
check = float((<$matKey$> & SCATTERING_MAP_BIT) != 0);
float <$scattering$> = check * fetchScatteringMap(<$texcoord0$>);
float <$scattering$> = float((<$matKey$> & SCATTERING_MAP_BIT) != 0) * fetchScatteringMap(<$texcoord0$>);
<@endif@>
<@endfunc@>
<@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmapVal)@>
<@if occlusion@>
float check1 = float((<$matKey$> & OCCLUSION_MAP_BIT) != 0);
float <$occlusion$> = check1 * fetchOcclusionMap(<$texcoord1$>) + (1.0 - check1);
float <$occlusion$> = mix(1.0, fetchOcclusionMap(<$texcoord1$>), float((<$matKey$> & OCCLUSION_MAP_BIT) != 0));
<@endif@>
<@if lightmapVal@>
vec3 <$lightmapVal$> = fetchLightmapMap(<$texcoord1$>);
@ -225,20 +217,19 @@ vec3 fetchLightmapMap(vec2 uv) {
<@func evalMaterialAlbedo(fetchedAlbedo, materialAlbedo, matKey, albedo)@>
{
float check = float((<$matKey$> & ALBEDO_VAL_BIT) != 0);
<$albedo$>.xyz = check * <$materialAlbedo$> + vec3(1.0 - check);
check = float((<$matKey$> & ALBEDO_MAP_BIT) != 0);
<$albedo$>.xyz *= check * <$fetchedAlbedo$>.xyz + vec3(1.0 - check);
<$albedo$>.xyz = mix(vec3(1.0), <$materialAlbedo$>, float((<$matKey$> & ALBEDO_VAL_BIT) != 0));
<$albedo$>.xyz *= mix(vec3(1.0), <$fetchedAlbedo$>.xyz, float((<$matKey$> & ALBEDO_MAP_BIT) != 0));
}
<@endfunc@>
<@func evalMaterialOpacity(fetchedOpacity, materialOpacity, matKey, opacity)@>
{
const float OPACITY_MASK_THRESHOLD = 0.5;
float check = float((<$matKey$> & (OPACITY_TRANSLUCENT_MAP_BIT | OPACITY_MASK_MAP_BIT)) != 0);
float check2 = float((<$matKey$> & OPACITY_MASK_MAP_BIT) != 0);
<$opacity$> = (check * (check2 * step(OPACITY_MASK_THRESHOLD, <$fetchedOpacity$>) + (1.0 - check2) * <$fetchedOpacity$>) + (1.0 - check)) * <$materialOpacity$>;
<$opacity$> = mix(1.0,
mix(<$fetchedOpacity$>,
step(OPACITY_MASK_THRESHOLD, <$fetchedOpacity$>),
float((<$matKey$> & OPACITY_MASK_MAP_BIT) != 0)),
float((<$matKey$> & (OPACITY_TRANSLUCENT_MAP_BIT | OPACITY_MASK_MAP_BIT)) != 0)) * <$materialOpacity$>;
}
<@endfunc@>
@ -259,22 +250,19 @@ vec3 fetchLightmapMap(vec2 uv) {
<@func evalMaterialRoughness(fetchedRoughness, materialRoughness, matKey, roughness)@>
{
float check = float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0);
<$roughness$> = check * <$fetchedRoughness$> + (1.0 - check) * <$materialRoughness$>;
<$roughness$> = mix(<$materialRoughness$>, <$fetchedRoughness$>, float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0));
}
<@endfunc@>
<@func evalMaterialMetallic(fetchedMetallic, materialMetallic, matKey, metallic)@>
{
float check = float((<$matKey$> & METALLIC_MAP_BIT) != 0);
<$metallic$> = check * <$fetchedMetallic$> + (1.0 - check) * <$materialMetallic$>;
<$metallic$> = mix(<$materialMetallic$>, <$fetchedMetallic$>, float((<$matKey$> & METALLIC_MAP_BIT) != 0));
}
<@endfunc@>
<@func evalMaterialEmissive(fetchedEmissive, materialEmissive, matKey, emissive)@>
{
float check = float((<$matKey$> & EMISSIVE_MAP_BIT) != 0);
<$emissive$> = check * <$fetchedEmissive$> + (1.0 - check) * <$materialEmissive$>;
<$emissive$> = mix(<$materialEmissive$>, <$fetchedEmissive$>, float((<$matKey$> & EMISSIVE_MAP_BIT) != 0));
}
<@endfunc@>
@ -286,8 +274,7 @@ vec3 fetchLightmapMap(vec2 uv) {
<@func evalMaterialScattering(fetchedScattering, materialScattering, matKey, scattering)@>
{
float check = float((<$matKey$> & SCATTERING_MAP_BIT) != 0);
<$scattering$> = check * <$fetchedScattering$> + (1.0 - check) * <$materialScattering$>;
<$scattering$> = mix(<$materialScattering$>, <$fetchedScattering$>, float((<$matKey$> & SCATTERING_MAP_BIT) != 0));
}
<@endfunc@>

View file

@ -30,11 +30,9 @@ void main(void) {
vec3 color = skybox.color.rgb;
// blend is only set if there is a cubemap
if (skybox.color.a > 0.0) {
color = texture(cubeMap, coord).rgb;
if (skybox.color.a < 1.0) {
color *= skybox.color.rgb;
}
}
float check = float(skybox.color.a > 0.0);
color = mix(color, texture(cubeMap, coord).rgb, check);
color *= mix(vec3(1.0), skybox.color.rgb, check * float(skybox.color.a < 1.0));
_fragColor = vec4(color, 0.0);
}

View file

@ -79,10 +79,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic);
frag.obscurance = min(specularVal.w, frag.obscurance);
float check = float(frag.mode == FRAG_MODE_SCATTERING);
frag.scattering = check * specularVal.x;
frag.scattering = float(frag.mode == FRAG_MODE_SCATTERING) * specularVal.x;
frag.fresnel = getFresnelF0(frag.metallic, diffuseVal.xyz);
return frag;
@ -121,10 +118,10 @@ DeferredFragment unpackDeferredFragmentNoPositionNoAmbient(vec2 texcoord) {
vec4 unpackDeferredPosition(float depthValue, vec2 texcoord) {
float check = float(isStereo());
float check2 = float(texcoord.x > 0.5);
texcoord.x -= check * check2 * 0.5;
int side = int(check * check2);
texcoord.x *= check * 2.0 + (1.0 - check) * 1.0;
float check2 = check * float(texcoord.x > 0.5);
texcoord.x -= check2 * 0.5;
int side = int(check2);
texcoord.x *= mix(1.0, 2.0, check);
return vec4(evalEyePositionFromZdb(side, depthValue, texcoord), 1.0);
}
@ -137,11 +134,13 @@ vec4 unpackDeferredPositionFromZdb(vec2 texcoord) {
vec4 unpackDeferredPositionFromZeye(vec2 texcoord) {
float Zeye = -texture(linearZeyeMap, texcoord).x;
float check = float(isStereo());
float check2 = float(texcoord.x > 0.5);
texcoord.x -= check * check2 * 0.5;
int side = int(check * check2);
texcoord.x *= check * 2.0 + (1.0 - check) * 1.0;
float check2 = check * float(texcoord.x > 0.5);
texcoord.x -= check2 * 0.5;
int side = int(check2);
texcoord.x *= mix(1.0, 2.0, check);
return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0);
}

View file

@ -34,9 +34,9 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness
}
float check = float(scattering > 0.0);
_fragColor0 = vec4(albedo, check * packScatteringMetallic(metallic) + (1.0 - check) * packShadedMetallic(metallic));
_fragColor0 = vec4(albedo, mix(packShadedMetallic(metallic), packScatteringMetallic(metallic), check));
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(check * vec3(scattering) + (1.0 - check) * emissive, occlusion);
_fragColor2 = vec4(mix(emissive, vec3(scattering), check), occlusion);
_fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0);
}

View file

@ -126,8 +126,7 @@ vec2 getSideImageSize(int resolutionLevel) {
ivec4 getStereoSideInfo(int xPos, int resolutionLevel) {
int sideWidth = int(getStereoSideWidth(resolutionLevel));
int check = int(xPos < sideWidth);
return ivec4((1 - check) * ivec2(1, sideWidth), sideWidth, isStereo());
return ivec4((1 - int(xPos < sideWidth)) * ivec2(1, sideWidth), sideWidth, isStereo());
}
float evalZeyeFromZdb(float depth) {

View file

@ -86,9 +86,7 @@ float evalFadeGradient(FadeObjectParams params, vec3 position) {
float evalFadeAlpha(FadeObjectParams params, vec3 position) {
float alpha = evalFadeGradient(params, position) - params.threshold;
float check = float(fadeParameters[params.category]._isInverted != 0);
alpha *= -check + (1.0 - check);
alpha *= mix(1.0, -1.0, float(fadeParameters[params.category]._isInverted != 0));
return alpha;
}

View file

@ -25,14 +25,13 @@ LAYOUT(binding=RENDER_UTILS_TEXTURE_HAZE_LINEAR_DEPTH) uniform sampler2D linearD
vec4 unpackPositionFromZeye(vec2 texcoord) {
float Zeye = -texture(linearDepthMap, texcoord).x;
int side = 0;
if (isStereo()) {
if (texcoord.x > 0.5) {
texcoord.x -= 0.5;
side = 1;
}
texcoord.x *= 2.0;
}
float check = float(isStereo());
float check2 = check * float(texcoord.x > 0.5);
texcoord.x -= check2 * 0.5;
int side = int(check2);
texcoord.x *= mix(1.0, 2.0, check);
return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0);
}

View file

@ -64,9 +64,8 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirectionWS, vec3
float height_95p = 2000.0;
const float log_p_005 = log(0.05);
{
float check = float(hazeParams.hazeKeyLightAltitudeFactor > 0.0f);
height_95p = check * -log_p_005 / hazeParams.hazeKeyLightAltitudeFactor + (1.0 - check) * height_95p;
if (hazeParams.hazeKeyLightAltitudeFactor > 0.0f) {
height_95p = -log_p_005 / hazeParams.hazeKeyLightAltitudeFactor;
}
// Note that we need the sine to be positive
@ -144,8 +143,7 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition
float deltaHeight = fragPositionWS.y - eyeWorldHeight;
float t = hazeParams.hazeHeightFactor * deltaHeight;
if (abs(t) > EPSILON) {
float check = float(abs(deltaHeight) > slopeThreshold);
hazeIntegral *= check * (1.0 - exp(-t)) / t + (1.0 - check);
hazeIntegral *= mix(1.0, (1.0 - exp(-t)) / t, float(abs(deltaHeight) > slopeThreshold));
}
vec3 hazeAmount = 1.0 - exp(-hazeIntegral);
@ -173,8 +171,7 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition
float deltaHeight = fragPositionWS.y - eyeWorldHeight;
float t = hazeParams.hazeHeightFactor * deltaHeight;
if (abs(t) > EPSILON) {
float check = float(abs(deltaHeight) > slopeThreshold);
hazeIntegral *= check * (1.0 - exp(-t)) / t + (1.0 - check);
hazeIntegral *= mix(1.0, (1.0 - exp(-t)) / t, float(abs(deltaHeight) > slopeThreshold));
}
float hazeAmount = 1.0 - exp(-hazeIntegral);
@ -186,8 +183,7 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition
// Mix with background at far range
const float BLEND_DISTANCE = 27000.0f;
vec4 outFragColor = potentialFragColor;
float check = float(distance > BLEND_DISTANCE);
outFragColor.a *= check * hazeParams.backgroundBlend + (1.0 - check);
outFragColor.a *= mix(1.0, hazeParams.backgroundBlend, float(distance > BLEND_DISTANCE));
return outFragColor;
}

View file

@ -45,9 +45,9 @@ void main(void) {
highlightedDepth = -evalZeyeFromZdb(highlightedDepth);
sceneDepth = -evalZeyeFromZdb(sceneDepth);
float check = float(sceneDepth < highlightedDepth);
outFragColor = check * vec4(params._fillOccludedColor, params._fillOccludedAlpha) +
(1.0 - check) * vec4(params._fillUnoccludedColor, params._fillUnoccludedAlpha);
outFragColor = mix(vec4(params._fillUnoccludedColor, params._fillUnoccludedAlpha),
vec4(params._fillOccludedColor, params._fillOccludedAlpha),
float(sceneDepth < highlightedDepth));
<@else@>
discard;
<@endif@>
@ -83,10 +83,7 @@ void main(void) {
}
}
{
float check = float(intensity > 0.0);
sumOutlineDepth = check * sumOutlineDepth + (1.0 - check) * FAR_Z;
}
sumOutlineDepth = mix(FAR_Z, sumOutlineDepth, float(intensity > 0.0));
intensity /= weight;
if (intensity < OPACITY_EPSILON) {
@ -102,11 +99,9 @@ void main(void) {
sceneDepth = -evalZeyeFromZdb(sceneDepth);
// Are we occluded?
{
float check = float(sceneDepth < outlinedDepth);
outFragColor = check * vec4(params._outlineOccludedColor, intensity * params._outlineOccludedAlpha) +
(1.0 - check) * vec4(params._outlineUnoccludedColor, intensity * params._outlineUnoccludedAlpha);
}
outFragColor = mix(vec4(params._outlineUnoccludedColor, intensity * params._outlineUnoccludedAlpha),
vec4(params._outlineOccludedColor, intensity * params._outlineOccludedAlpha),
float(sceneDepth < outlinedDepth));
}
}

View file

@ -83,8 +83,7 @@ int clusterGrid_getClusterLightId(int index, int offset) {
return element;
*/
int element = _clusterGridContent[GRID_FETCH_BUFFER((elementIndex >> 1))];
int check = int((elementIndex & 0x00000001) == 1);
return (check * (element >> 16) + (1 - check) * element) & 0x0000FFFF;
return int(mix(element, element >> 16, int((elementIndex & 0x00000001) == 1))) & 0x0000FFFF;
}

View file

@ -7,8 +7,12 @@
#ifdef __cplusplus
# define _MIN glm::min
# define _MIX(x, y, a) glm::mix((float)x, (float)y, (float)a)
# define _ABS(x) (int)fabsf()
#else
# define _MIN min
# define _MIX mix
# define _ABS abs
#endif
float frustumGrid_depthRampGridToVolume(float ngrid) {
@ -124,7 +128,7 @@ ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) {
// make sure the frontEyePos is always in the front to eval the grid pos correctly
vec3 frontEyePos = eyePos;
frontEyePos.z = -abs(eyePos.z);
frontEyePos.z = -_ABS(eyePos.z);
vec3 volumePos = frustumGrid_eyeToVolume(frontEyePos, frustumGrid.eyeToGridProj, frustumGrid.rangeNear, frustumGrid.rangeFar);
@ -147,8 +151,7 @@ ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) {
int frustumGrid_eyeToClusterDirH(vec3 eyeDir) {
if (eyeDir.z >= 0.0f) {
int check = int(eyeDir.x > 0.0f);
return check * frustumGrid.dims.x + (check - 1);
return int(_MIX(-1, frustumGrid.dims.x, int(eyeDir.x > 0.0f)));
}
float eyeDepth = -eyeDir.z;
@ -162,8 +165,7 @@ int frustumGrid_eyeToClusterDirH(vec3 eyeDir) {
int frustumGrid_eyeToClusterDirV(vec3 eyeDir) {
if (eyeDir.z >= 0.0f) {
int check = int(eyeDir.y > 0.0f);
return check * frustumGrid.dims.y + (check - 1);
return int(_MIX(-1, frustumGrid.dims.y, int(eyeDir.y > 0.0f)));
}
float eyeDepth = -eyeDir.z;

View file

@ -39,14 +39,11 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light,
lightEnergy *= isPointEnabled();
diffuse *= lightEnergy * isDiffuseEnabled();
specular *= lightEnergy * isSpecularEnabled();
{
// Show edges
float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0);
float check = float(isShowLightContour() > 0.0 && edge < 1.0);
float edgeCoord = exp2(-8.0 * edge * edge);
diffuse = check * vec3(edgeCoord * edgeCoord * getLightColor(light)) + (1.0 - check) * diffuse;
}
// Show edges
float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0);
float edgeCoord = exp2(-8.0 * edge * edge);
diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(isShowLightContour() > 0.0 && edge < 1.0));
}
<@endfunc@>
@ -59,13 +56,10 @@ bool evalLightPointEdge(out vec3 color, Light light, vec4 fragLightDirLen, vec3
float fragLightDistance = fragLightDirLen.w;
vec3 fragLightDir = fragLightDirLen.xyz;
// Show edges
float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0);
{
// Show edges
float check = float(edge < 1.0);
float edgeCoord = exp2(-8.0 * edge * edge);
color = check * vec3(edgeCoord * edgeCoord * getLightColor(light)) + (1.0 - check) * color;
}
float edgeCoord = exp2(-8.0 * edge * edge);
color = mix(color, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0));
return (edge < 1.0);
}

View file

@ -40,17 +40,14 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light,
lightEnergy *= isSpotEnabled();
diffuse *= lightEnergy * isDiffuseEnabled();
specular *= lightEnergy * isSpecularEnabled();
{
// Show edges
float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance);
float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume));
float edgeDist = min(edgeDistR, edgeDistS);
float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0);
float check = float(isShowLightContour() > 0.0 && edge < 1.0);
float edgeCoord = exp2(-8.0 * edge * edge);
diffuse = check * vec3(edgeCoord * edgeCoord * getLightColor(light)) + (1.0 - check) * diffuse;
}
// Show edges
float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance);
float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume));
float edgeDist = min(edgeDistR, edgeDistS);
float edge = abs(2.0 * (edgeDist * 10.0) - 1.0);
float edgeCoord = exp2(-8.0 * edge * edge);
diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(isShowLightContour() > 0.0 && edge < 1.0));
}
<@endfunc@>
@ -62,16 +59,13 @@ bool evalLightSpotEdge(out vec3 color, Light light, vec4 fragLightDirLen, float
float fragLightDistance = fragLightDirLen.w;
vec3 fragLightDir = fragLightDirLen.xyz;
// Show edges
float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance);
float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume));
float edgeDist = min(edgeDistR, edgeDistS);
float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0);
{
// Show edges
float check = float(edge < 1.0);
float edgeCoord = exp2(-8.0 * edge * edge);
color = check * vec3(edgeCoord * edgeCoord * getLightColor(light)) + (1.0 - check) * color;
}
float edge = abs(2.0 * (edgeDist * 10.0) - 1.0);
float edgeCoord = exp2(-8.0 * edge * edge);
color = mix(color, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0));
return (edge < 1.0);
}

View file

@ -115,22 +115,10 @@ float evalShadowAttenuation(vec3 worldLightDir, vec4 worldPosition, float viewDe
isPixelOnCascade.z = isShadowCascadeProjectedOnPixel(cascadeShadowCoords[2]);
isPixelOnCascade.w = isShadowCascadeProjectedOnPixel(cascadeShadowCoords[3]);
{
float check = float(isPixelOnCascade.x);
cascadeAttenuations.x = check * evalShadowCascadeAttenuation(0, offsets, cascadeShadowCoords[0], oneMinusNdotL) + (1.0 - check);
}
{
float check = float(isPixelOnCascade.y);
cascadeAttenuations.y = check * evalShadowCascadeAttenuation(1, offsets, cascadeShadowCoords[1], oneMinusNdotL) + (1.0 - check);
}
{
float check = float(isPixelOnCascade.z);
cascadeAttenuations.z = check * evalShadowCascadeAttenuation(2, offsets, cascadeShadowCoords[2], oneMinusNdotL) + (1.0 - check);
}
{
float check = float(isPixelOnCascade.w);
cascadeAttenuations.w = check * evalShadowCascadeAttenuation(3, offsets, cascadeShadowCoords[3], oneMinusNdotL) + (1.0 - check);
}
cascadeAttenuations.x = mix(1.0, evalShadowCascadeAttenuation(0, offsets, cascadeShadowCoords[0], oneMinusNdotL), float(isPixelOnCascade.x));
cascadeAttenuations.y = mix(1.0, evalShadowCascadeAttenuation(1, offsets, cascadeShadowCoords[1], oneMinusNdotL), float(isPixelOnCascade.y));
cascadeAttenuations.z = mix(1.0, evalShadowCascadeAttenuation(2, offsets, cascadeShadowCoords[2], oneMinusNdotL), float(isPixelOnCascade.z));
cascadeAttenuations.w = mix(1.0, evalShadowCascadeAttenuation(3, offsets, cascadeShadowCoords[3], oneMinusNdotL), float(isPixelOnCascade.w));
cascadeWeights.x = evalShadowCascadeWeight(cascadeShadowCoords[0]);
cascadeWeights.y = evalShadowCascadeWeight(cascadeShadowCoords[1]);

View file

@ -81,9 +81,7 @@ void evalSkinning(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPositio
// to ensure that we rotate along the shortest arc, reverse dual quaternions with negative polarity.
float dqClusterWeight = clusterWeight;
if (dot(real, polarityReference) < 0.0) {
dqClusterWeight = -clusterWeight;
}
dqClusterWeight *= mix(1.0, -1.0, float(dot(real, polarityReference) < 0.0));
sAccum += scale * clusterWeight;
rAccum += real * dqClusterWeight;
@ -102,12 +100,11 @@ void evalSkinning(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPositio
// sAccum.w indicates the amount of cauterization for this vertex.
// 0 indicates no cauterization and 1 indicates full cauterization.
// TODO: make this cauterization smoother or implement full dual-quaternion scale support.
const float CAUTERIZATION_THRESHOLD = 0.1;
if (sAccum.w > CAUTERIZATION_THRESHOLD) {
skinnedPosition = cAccum;
} else {
sAccum.w = 1.0;
skinnedPosition = m * (sAccum * inPosition);
{
const float CAUTERIZATION_THRESHOLD = 0.1;
float check = float(sAccum.w > CAUTERIZATION_THRESHOLD);
sAccum.w = mix(1.0, sAccum.w, check);
skinnedPosition = mix(m * (sAccum * inPosition), cAccum, check);
}
<@if USE_NORMAL@>

View file

@ -82,8 +82,6 @@ vec3 integrate(float cosTheta, float skinRadius) {
while (a <= (_PI)) {
float sampleAngle = theta + a;
float diffuse = clamp(cos(sampleAngle), 0.0, 1.0);
//if (diffuse < 0.0) diffuse = 0.0;
//if (diffuse > 1.0) diffuse = 1.0;
// Distance.
float sampleDist = abs(2.0 * skinRadius * sin(a * 0.5));
@ -180,7 +178,8 @@ vec3 evalSkinBRDF(vec3 lightDir, vec3 normal, vec3 midNormal, vec3 lowNormal, fl
return lowNormal * 0.5 + vec3(0.5);
}
if (showCurvature()) {
return (curvature > 0.0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature));
float check = float(curvature > 0.0);
return vec3(check * curvature, 0.0, (1.0 - check) * -curvature);
}
vec3 bentNdotL = evalScatteringBentNdotL(normal, midNormal, lowNormal, lightDir);

View file

@ -37,9 +37,7 @@ void main(void) {
#ifdef GPU_TRANSFORM_IS_STEREO
#ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN
#else
if (cam_isStereo()) {
projected.x = 0.5 * (projected.x + cam_getStereoSide());
}
projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo()));
#endif
#endif
_texCoord01 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w;
@ -66,9 +64,7 @@ void main(void) {
#ifdef GPU_TRANSFORM_IS_STEREO
#ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN
#else
if (cam_isStereo()) {
_texCoord01.x = 0.5 * (_texCoord01.x + cam_getStereoSide());
}
_texCoord01.x = mix(_texCoord01.x, 0.5 * (_texCoord01.x + cam_getStereoSide()), float(cam_isStereo()));
#endif
#endif

View file

@ -47,8 +47,6 @@ void main(void) {
vec4 projected = gl_Position / gl_Position.w;
projected.xy = (projected.xy + 1.0) * 0.5;
if (cam_isStereo()) {
projected.x = 0.5 * (projected.x + cam_getStereoSide());
}
projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo()));
_texCoord0 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w;
}

View file

@ -60,9 +60,7 @@ void main(void) {
#ifdef GPU_TRANSFORM_IS_STEREO
#ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN
#else
if (cam_isStereo()) {
projected.x = 0.5 * (projected.x + cam_getStereoSide());
}
projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo()));
#endif
#endif
_texCoord0 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w;

View file

@ -33,16 +33,15 @@ void main(void) {
float shadowAttenuation = 1.0;
if (frag.mode == FRAG_MODE_UNLIT) {
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
discard;
} else {
vec4 midNormalCurvature = vec4(0);
vec4 lowNormalCurvature = vec4(0);
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
float check = float(frag.mode == FRAG_MODE_SCATTERING);
midNormalCurvature = check * midNormalCurvature;
lowNormalCurvature = check * lowNormalCurvature;
vec3 color = evalAmbientSphereGlobalColor(
getViewInverse(),

View file

@ -35,16 +35,16 @@ void main(void) {
vec3 worldLightDirection = getLightDirection(shadowLight);
float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal);
if (frag.mode == FRAG_MODE_UNLIT) {
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
discard;
} else {
vec4 midNormalCurvature = vec4(0);
vec4 lowNormalCurvature = vec4(0);
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
float check = float(frag.mode == FRAG_MODE_SCATTERING);
midNormalCurvature = check * midNormalCurvature;
lowNormalCurvature = check * lowNormalCurvature;
vec3 color = evalAmbientSphereGlobalColor(
getViewInverse(),
shadowAttenuation,

View file

@ -31,16 +31,16 @@ void main(void) {
float shadowAttenuation = 1.0;
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) {
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
discard;
} else {
vec4 midNormalCurvature = vec4(0);
vec4 lowNormalCurvature = vec4(0);
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
float check = float(frag.mode == FRAG_MODE_SCATTERING);
midNormalCurvature = check * midNormalCurvature;
lowNormalCurvature = check * lowNormalCurvature;
vec3 color = evalSkyboxGlobalColor(
getViewInverse(),
shadowAttenuation,

View file

@ -36,16 +36,16 @@ void main(void) {
float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal);
// Light mapped or not ?
if (frag.mode == FRAG_MODE_UNLIT) {
discard;
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) {
discard;
} else {
vec4 midNormalCurvature = vec4(0);
vec4 lowNormalCurvature = vec4(0);
if (frag.mode == FRAG_MODE_SCATTERING) {
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
}
unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature);
float check = float(frag.mode == FRAG_MODE_SCATTERING);
midNormalCurvature = check * midNormalCurvature;
lowNormalCurvature = check * lowNormalCurvature;
vec3 color = evalSkyboxGlobalColor(
getViewInverse(),
shadowAttenuation,

View file

@ -62,7 +62,5 @@ void main(void) {
varColor = vec4(REGION_COLOR[region].xyz, proxy.sphere.w);
if (region == 4) {
gl_Position = vec4(0.0);
}
gl_Position = mix(gl_Position, vec4(0.0), float(region == 4));
}

View file

@ -40,8 +40,5 @@ void main(void) {
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
albedo *= _color.rgb;
if (opacity != 1.0) {
discard;
}
_fragColor0 = vec4(albedo * isUnlitEnabled(), 1.0);
}

View file

@ -53,13 +53,9 @@ void main(void) {
// Add or subtract the orthogonal vector based on a different vertex ID
// calculation
if (gl_VertexID < 2) {
distanceFromCenter = -1.0;
eye.xyz -= orthogonal;
} else {
distanceFromCenter = 1.0;
eye.xyz += orthogonal;
}
float check = float(gl_VertexID < 2);
distanceFromCenter = mix(1.0, -1.0, check);
eye.xyz += mix(orthogonal, -orthogonal, check);
// Finally, put the eyespace vertex into clip space
<$transformEyeToClipPos(cam, eye, gl_Position)$>

View file

@ -34,12 +34,10 @@ layout(location=0) out vec4 outFragColor;
void main(void) {
Grid grid = getGrid();
float alpha;
if (grid.edge.z == 0.0) {
alpha = paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.edge.xy);
} else {
alpha = paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge);
}
float alpha = mix(paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge),
paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.edge.xy),
float(grid.edge.z == 0.0));
if (alpha == 0.0) {
discard;
}

View file

@ -90,6 +90,6 @@ void main(void) {
numLightTouching++;
}
_fragColor = vec4(colorRamp(1.0 - (float(numLightTouching) / 12.0f)), (numLightTouching > 0 ? 0.5 + 0.5 * numLightsScale : 0.0));
_fragColor = vec4(colorRamp(1.0 - (float(numLightTouching) / 12.0f)), float(numLightTouching > 0) * (0.5 + 0.5 * numLightsScale));
}

View file

@ -69,5 +69,5 @@ void main(void) {
TransformCamera cam = getTransformCamera();
<$transformWorldToClipPos(cam, worldPos, gl_Position)$>
varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), (numLights >0 ? 0.9 : 0.1));
varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), mix(0.1, 0.9, float(numLights > 0)));
}

View file

@ -62,12 +62,10 @@ void main(void) {
float relClusterId = float(clusterPos.z * summedDims.x + clusterPos.y * summedDims.y + clusterPos.x) / float(frustumGrid_numClusters());
if (relClusterId < 0.0) {
_fragColor = vec4(0.0);
} else if (relClusterId >= 1.0) {
_fragColor = vec4(vec3(1.0), 0.2);
} else {
_fragColor = vec4(colorWheel(fract(relClusterId)), (numLights > 0 ? 0.05 + 0.95 * numLightsScale : 0.0));
}
_fragColor = mix(mix(vec4(colorWheel(fract(relClusterId)), float(numLights > 0) * (0.05 + 0.95 * numLightsScale)),
vec4(vec3(1.0), 0.2),
float(relClusterId >= 1.0)),
vec4(0.0),
float(relClusterId < 0.0));
}

View file

@ -62,5 +62,5 @@ void main(void) {
TransformCamera cam = getTransformCamera();
<$transformWorldToClipPos(cam, worldPos, gl_Position)$>
varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.9);
varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.9);
}

View file

@ -69,5 +69,5 @@ void main(void) {
TransformCamera cam = getTransformCamera();
<$transformWorldToClipPos(cam, worldPos, gl_Position)$>
varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), (numLights > 0 ? 0.9 : 0.0));
varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), float(numLights > 0) * 0.9);
}

View file

@ -96,9 +96,8 @@ void main(void) {
vec3 fragLightDir = fragLightDirLen.xyz;
vec3 color = vec3(0.0);
if (evalLightPointEdge(color, light, fragLightDirLen, fragEyeDir)) {
_fragColor.rgb += color;
}
float check = float(evalLightPointEdge(color, light, fragLightDirLen, fragEyeDir));
_fragColor.rgb += check * color;
}
for (int i = cluster.x; i < numLights; i++) {
@ -130,10 +129,8 @@ void main(void) {
numLightTouching++;
vec3 color = vec3(0.0);
if (evalLightSpotEdge(color, light, fragLightDirLen, cosSpotAngle, fragEyeDir)) {
_fragColor.rgb += color;
}
float check = float(evalLightSpotEdge(color, light, fragLightDirLen, cosSpotAngle, fragEyeDir));
_fragColor.rgb += check * color;
}
}

View file

@ -48,11 +48,8 @@ void main(void) {
} else {
normal = vec4(normalize(cross(_parabolaData.velocity, _parabolaData.acceleration)), 0);
}
if (gl_VertexID % 2 == 0) {
pos += 0.5 * _parabolaData.width * normal;
} else {
pos -= 0.5 * _parabolaData.width * normal;
}
pos += 0.5 * _parabolaData.width * normal * mix(-1.0, 1.0, float(gl_VertexID % 2 == 0));
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
}

View file

@ -39,13 +39,8 @@ const float taaBias = pow(2.0, TAA_TEXTURE_LOD_BIAS);
float evalSDF(vec2 texCoord) {
// retrieve signed distance
float sdf = textureLod(Font, texCoord, TAA_TEXTURE_LOD_BIAS).g;
if (params.outline.x > 0.0) {
if (sdf > interiorCutoff) {
sdf = 1.0 - sdf;
} else {
sdf += outlineExpansion;
}
}
sdf = mix(sdf, mix(sdf + outlineExpansion, 1.0 - sdf, float(sdf > interiorCutoff)), float(params.outline.x > 0.0));
// Rely on TAA for anti-aliasing
return step(0.5, sdf);
}
@ -57,16 +52,11 @@ void main() {
// Perform 4x supersampling for anisotropic filtering
float a;
a = evalSDF(_texCoord0);
a += evalSDF(_texCoord0+dxTexCoord);
a += evalSDF(_texCoord0+dyTexCoord);
a += evalSDF(_texCoord0+dxTexCoord+dyTexCoord);
a += evalSDF(_texCoord0 + dxTexCoord);
a += evalSDF(_texCoord0 + dyTexCoord);
a += evalSDF(_texCoord0 + dxTexCoord + dyTexCoord);
a *= 0.25;
// discard if invisible
if (a < 0.01) {
discard;
}
packDeferredFragment(
normalize(_normalWS),
a * params.color.a,

View file

@ -30,31 +30,32 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
#define _texCoord0 _texCoord01.xy
#define _texCoord1 _texCoord01.zw
const float gamma = 2.2;
const float smoothing = 32.0;
#define TAA_TEXTURE_LOD_BIAS -3.0
const float interiorCutoff = 0.8;
const float outlineExpansion = 0.2;
const float taaBias = pow(2.0, TAA_TEXTURE_LOD_BIAS);
float evalSDF(vec2 texCoord) {
// retrieve signed distance
float sdf = textureLod(Font, texCoord, TAA_TEXTURE_LOD_BIAS).g;
sdf = mix(sdf, mix(sdf + outlineExpansion, 1.0 - sdf, float(sdf > interiorCutoff)), float(params.outline.x > 0.0));
// Rely on TAA for anti-aliasing
return step(0.5, sdf);
}
void main() {
// retrieve signed distance
float sdf = texture(Font, _texCoord0).g;
if (params.outline.x > 0.0) {
if (sdf > interiorCutoff) {
sdf = 1.0 - sdf;
} else {
sdf += outlineExpansion;
}
}
// perform adaptive anti-aliasing of the edges
// The larger we're rendering, the less anti-aliasing we need
float s = smoothing * length(fwidth(_texCoord0));
float w = clamp(s, 0.0, 0.5);
float a = smoothstep(0.5 - w, 0.5 + w, sdf);
// discard if invisible
if (a < 0.01) {
discard;
}
vec2 dxTexCoord = dFdx(_texCoord0) * 0.5 * taaBias;
vec2 dyTexCoord = dFdy(_texCoord0) * 0.5 * taaBias;
// Perform 4x supersampling for anisotropic filtering
float a;
a = evalSDF(_texCoord0);
a += evalSDF(_texCoord0 + dxTexCoord);
a += evalSDF(_texCoord0 + dyTexCoord);
a += evalSDF(_texCoord0 + dxTexCoord + dyTexCoord);
a *= 0.25;
packDeferredFragmentTranslucent(
normalize(_normalWS),

View file

@ -54,7 +54,7 @@ void main(void) {
vec3 specular = DEFAULT_SPECULAR;
float shininess = DEFAULT_SHININESS;
float emissiveAmount = 0.0;
#ifdef PROCEDURAL
#ifdef PROCEDURAL_V1

View file

@ -12,6 +12,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include gpu/Color.slh@>
<@include DeferredBufferWrite.slh@>
<@include render-utils/ShaderConstants.h@>
@ -28,11 +29,13 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
void main(void) {
vec4 texel = texture(originalTexture, _texCoord0);
texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0));
texel.rgb *= _color.rgb;
packDeferredFragment(
normalize(_normalWS),
1.0,
_color.rgb * texel.rgb,
texel.rgb,
DEFAULT_ROUGHNESS,
DEFAULT_METALLIC,
DEFAULT_EMISSIVE,

View file

@ -39,27 +39,25 @@ void main(void) {
<$fetchFadeObjectParamsInstanced(fadeParams)$>
applyFade(fadeParams, _positionWS.xyz, fadeEmissive);
vec4 texel = texture(originalTexture, _texCoord0);
float colorAlpha = _color.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
colorAlpha = -_color.a;
}
texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0));
texel.rgb *= _color.rgb;
texel.a = abs(_color.a);
const float ALPHA_THRESHOLD = 0.999;
if (colorAlpha * texel.a < ALPHA_THRESHOLD) {
if (texel.a < ALPHA_THRESHOLD) {
packDeferredFragmentTranslucent(
normalize(_normalWS),
colorAlpha * texel.a,
_color.rgb * texel.rgb + fadeEmissive,
texel.a,
texel.rgb + fadeEmissive,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
} else {
packDeferredFragment(
normalize(_normalWS),
1.0,
_color.rgb * texel.rgb,
texel.rgb,
DEFAULT_ROUGHNESS,
DEFAULT_METALLIC,
DEFAULT_EMISSIVE + fadeEmissive,

View file

@ -28,25 +28,23 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
#define _texCoord1 _texCoord01.zw
void main(void) {
vec4 texel = texture(originalTexture, _texCoord0.st);
float colorAlpha = _color.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
colorAlpha = -_color.a;
}
vec4 texel = texture(originalTexture, _texCoord0);
texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0));
texel.rgb *= _color.rgb;
texel.a = abs(_color.a);
const float ALPHA_THRESHOLD = 0.999;
if (colorAlpha * texel.a < ALPHA_THRESHOLD) {
if (texel.a < ALPHA_THRESHOLD) {
packDeferredFragmentTranslucent(
normalize(_normalWS),
colorAlpha * texel.a,
_color.rgb * texel.rgb,
texel.a,
texel.rgb,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
} else {
packDeferredFragmentUnlit(
normalize(_normalWS),
1.0,
_color.rgb * texel.rgb);
texel.rgb);
}
}

View file

@ -40,25 +40,23 @@ void main(void) {
<$fetchFadeObjectParamsInstanced(fadeParams)$>
applyFade(fadeParams, _positionWS.xyz, fadeEmissive);
vec4 texel = texture(originalTexture, _texCoord0.st);
float colorAlpha = _color.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
colorAlpha = -_color.a;
}
vec4 texel = texture(originalTexture, _texCoord0);
texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0));
texel.rgb *= _color.rgb;
texel.a = abs(_color.a);
const float ALPHA_THRESHOLD = 0.999;
if (colorAlpha * texel.a < ALPHA_THRESHOLD) {
if (texel.a < ALPHA_THRESHOLD) {
packDeferredFragmentTranslucent(
normalize(_normalWS),
colorAlpha * texel.a,
_color.rgb * texel.rgb+fadeEmissive,
texel.a,
texel.rgb + fadeEmissive,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
} else {
packDeferredFragmentUnlit(
normalize(_normalWS),
1.0,
_color.rgb * texel.rgb+fadeEmissive);
texel.rgb + fadeEmissive);
}
}

View file

@ -12,6 +12,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include gpu/Color.slh@>
<@include DeferredBufferWrite.slh@>
<@include render-utils/ShaderConstants.h@>
@ -28,12 +29,14 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
void main(void) {
vec4 texel = texture(originalTexture, _texCoord0);
float colorAlpha = _color.a * texel.a;
texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0));
texel.rgb *= _color.rgb;
texel.a *= abs(_color.a);
packDeferredFragmentTranslucent(
normalize(_normalWS),
colorAlpha,
_color.rgb * texel.rgb,
texel.a,
texel.rgb,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
}

View file

@ -46,14 +46,10 @@ void main(void) {
<$fetchFadeObjectParamsInstanced(fadeParams)$>
applyFade(fadeParams, _positionWS.xyz, fadeEmissive);
vec4 texel = texture(originalTexture, _texCoord0.st);
float opacity = _color.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
opacity = -_color.a;
}
opacity *= texel.a;
vec3 albedo = _color.rgb * texel.rgb;
vec4 texel = texture(originalTexture, _texCoord0);
texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0));
texel.rgb *= _color.rgb;
texel.a *= abs(_color.a);
vec3 fragPosition = _positionES.xyz;
vec3 fragNormal = normalize(_normalWS);
@ -66,12 +62,11 @@ void main(void) {
1.0,
fragPosition,
fragNormal,
albedo,
texel.rgb,
DEFAULT_FRESNEL,
0.0f,
fadeEmissive,
DEFAULT_ROUGHNESS,
opacity),
opacity);
texel.a),
texel.a);
}

View file

@ -27,11 +27,10 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01;
layout(location=0) out vec4 _fragColor0;
void main(void) {
vec4 texel = texture(originalTexture, _texCoord0.st);
float colorAlpha = _color.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
colorAlpha = -_color.a;
}
_fragColor0 = vec4(_color.rgb * texel.rgb, colorAlpha * texel.a);
vec4 texel = texture(originalTexture, _texCoord0);
texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0));
texel.rgb *= _color.rgb;
texel.a *= abs(_color.a);
_fragColor0 = texel;
}

View file

@ -39,11 +39,10 @@ void main(void) {
<$fetchFadeObjectParamsInstanced(fadeParams)$>
applyFade(fadeParams, _positionWS.xyz, fadeEmissive);
vec4 texel = texture(originalTexture, _texCoord0.st);
float colorAlpha = _color.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
colorAlpha = -_color.a;
}
_fragColor0 = vec4(_color.rgb * texel.rgb + fadeEmissive, colorAlpha * texel.a);
vec4 texel = texture(originalTexture, _texCoord0);
texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0));
texel.rgb *= _color.rgb;
texel.a *= abs(_color.a);
_fragColor0 = vec4(texel.rgb + fadeEmissive, texel.a);
}

View file

@ -183,43 +183,24 @@ vec3 getTapLocationClamped(int sampleNumber, float spinAngle, float outerRadius,
}
bool redoTap = false;
if ((tapPos.x < 0.5)) {
tapPos.x = -tapPos.x;
redoTap = true;
} else if ((tapPos.x > imageSize.x - 0.5)) {
tapPos.x -= (imageSize.x - tapPos.x);
redoTap = true;
{
float check1 = float(tapPos.x < 0.5);
float check2 = (1.0 - check1) * float(tapPos.x > imageSize.x - 0.5);
tapPos.x = mix(tapPos.x, -tapPos.x, check1) - check2 * (imageSize.x - tapPos.x);
redoTap = (check1 > 0.0 || check2 > 0.0);
}
if ((tapPos.y < 0.5)) {
tapPos.y = -tapPos.y;
redoTap = true;
} else if ((tapPos.y > imageSize.y - 0.5)) {
tapPos.y -= (imageSize.y - tapPos.y);
redoTap = true;
}
/*
if ((tapPos.x < 0.5)) {
tapPos.x = 0.5;
redoTap = true;
} else if ((tapPos.x > imageSize.x - 0.5)) {
tapPos.x = imageSize.x - 0.5;
redoTap = true;
{
float check1 = float(tapPos.y < 0.5);
float check2 = (1.0 - check1) * float(tapPos.y > imageSize.y - 0.5);
tapPos.y = mix(tapPos.y, -tapPos.y, check1) - check2 * (imageSize.y - tapPos.y);
redoTap = (check1 > 0.0 || check2 > 0.0);
}
if ((tapPos.y < 0.5)) {
tapPos.y = 0.5;
redoTap = true;
} else if ((tapPos.y > imageSize.y - 0.5)) {
tapPos.y = imageSize.y - 0.5;
redoTap = true;
}
*/
if (redoTap) {
tap.xy = tapPos - pixelPos;
tap.z = length(tap.xy);
tap.z = 0.0;
{
float check = float(redoTap);
tap.xy = mix(tap.xy, tapPos - pixelPos, check);
tap.z = (1.0 - check) * tap.z;
}
return tap;

View file

@ -40,9 +40,9 @@ void main(void) {
vec2 imageSize = getSideImageSize(getResolutionLevel());
// In debug adjust the correct frag pixel based on base resolution
vec2 fragCoord = gl_FragCoord.xy;
vec2 fragCoord = gl_FragCoord.xy;
if (getResolutionLevel() > 0) {
fragCoord /= float (1 << getResolutionLevel());
fragCoord /= float(1 << getResolutionLevel());
}
// Pixel Debugged
@ -90,10 +90,11 @@ void main(void) {
// The occluding point in camera space
vec2 fragToTap = vec2(ssC) + tap.xy - fragCoord.xy;
if (dot(fragToTap,fragToTap) < keepTapRadius) {
keep = true;
keepedMip = evalMipFromRadius(tap.z * float(doFetchMips()));
}
{
bool check = dot(fragToTap,fragToTap) < keepTapRadius;
keep = keep || check;
keepedMip = int(mix(keepedMip, evalMipFromRadius(tap.z * float(doFetchMips())), int(check)));
}
vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize);
@ -108,12 +109,8 @@ void main(void) {
<! // KEEP IT for Debugging
// Bilateral box-filter over a quad for free, respecting depth edges
// (the difference that this makes is subtle)
if (abs(dFdx(Cp.z)) < 0.02) {
A -= dFdx(A) * ((ssC.x & 1) - 0.5);
}
if (abs(dFdy(Cp.z)) < 0.02) {
A -= dFdy(A) * ((ssC.y & 1) - 0.5);
}
A -= float(abs(dFdx(Cp.z)) < 0.02) * dFdx(A) * ((ssC.x & 1) - 0.5);
A -= float(abs(dFdy(Cp.z)) < 0.02) * dFdy(A) * ((ssC.y & 1) - 0.5);
!>
outFragColor = vec4(packOcclusionDepth(A, CSZToDephtKey(Cp.z)), 1.0);
@ -124,9 +121,5 @@ void main(void) {
return;
}
if (!keep) {
outFragColor = vec4(0.1);
} else {
outFragColor.rgb = colorWheel(float(keepedMip)/float(MAX_MIP_LEVEL));
}
outFragColor = mix(vec4(0.1), vec4(colorWheel(float(keepedMip) / float(MAX_MIP_LEVEL)), outFragColor.a), float(keep));
}

View file

@ -68,13 +68,8 @@ void main(void) {
// KEEP IT for Debugging
// Bilateral box-filter over a quad for free, respecting depth edges
// (the difference that this makes is subtle)
if (abs(dFdx(Cp.z)) < 0.02) {
A -= dFdx(A) * (float(ssC.x & 1) - 0.5);
}
if (abs(dFdy(Cp.z)) < 0.02) {
A -= dFdy(A) * (float(ssC.y & 1) - 0.5);
}
A -= float(abs(dFdx(Cp.z)) < 0.02) * dFdx(A) * (float(ssC.x & 1) - 0.5);
A -= float(abs(dFdy(Cp.z)) < 0.02) * dFdy(A) * (float(ssC.y & 1) - 0.5);
outFragColor = vec4(packOcclusionDepth(A, CSZToDephtKey(Cp.z)), 1.0);

View file

@ -18,6 +18,9 @@ float aspectRatio = 0.95;
void main(void) {
vec2 pos = varTexCoord0 * 2.0 - vec2(1.0);
pos.x = aspectRatio * (pos.x * (pos.x > 0.0 ? 2.0 : -2.0) - 1.0);
if (1.0 - dot(pos.xy, pos.xy) > 0.0 ) discard;
pos.x = aspectRatio * (pos.x * mix(-2.0, 2.0, float(pos.x > 0.0)) - 1.0);
if (1.0 - dot(pos.xy, pos.xy) > 0.0) {
discard;
}
}

View file

@ -93,14 +93,14 @@ vec3 drawScatteringTableUV(vec2 cursor, vec2 texcoord) {
vec3 color = vec3(0.0);
bool keep = false;
for (int c = 0; c < 3; c++) {
if (distance[c] > threshold) {
keep = true;
color[c] += 1.0;
}
bool check = distance[c] > threshold;
keep = keep || check;
color[c] += float(check);
}
if (!keep)
discard;
if (!keep) {
discard;
}
return color;
}

View file

@ -67,11 +67,7 @@ vec3 getRawNormal(vec2 texcoord) {
vec3 getWorldNormal(vec2 texcoord) {
vec3 rawNormal = getRawNormal(texcoord);
if (isFullResolution()) {
return unpackNormal(rawNormal);
} else {
return normalize((rawNormal - vec3(0.5)) * 2.0);
}
return mix(normalize((rawNormal - vec3(0.5)) * 2.0), unpackNormal(rawNormal), float(isFullResolution()));
}
vec3 getWorldNormalDiff(vec2 texcoord, vec2 delta) {
@ -93,7 +89,7 @@ void main(void) {
vec2 texcoordPos;
ivec4 stereoSide;
ivec2 framePixelPos = getPixelPosTexcoordPosAndSide(gl_FragCoord.xy, pixelPos, texcoordPos, stereoSide);
vec2 stereoSideClip = vec2(stereoSide.x, (isStereo() ? 0.5 : 1.0));
vec2 stereoSideClip = vec2(stereoSide.x, mix(1.0, 0.5, float(isStereo())));
// Texcoord to fetch in the deferred texture are the exact UVs comming from vertex shader
// sideToFrameTexcoord(stereoSideClip, texcoordPos);
@ -128,8 +124,8 @@ void main(void) {
// Calculate dF/du and dF/dv
vec2 viewportScale = perspectiveScale * getInvWidthHeight();
vec2 du = vec2( viewportScale.x * (float(stereoSide.w) > 0.0 ? 0.5 : 1.0), 0.0f );
vec2 dv = vec2( 0.0f, viewportScale.y );
vec2 du = vec2(viewportScale.x * mix(1.0, 0.5, float(float(stereoSide.w) > 0.0)), 0.0);
vec2 dv = vec2( 0.0f, viewportScale.y);
vec4 dFdu = vec4(getWorldNormalDiff(frameTexcoordPos, du), getEyeDepthDiff(frameTexcoordPos, du));
vec4 dFdv = vec4(getWorldNormalDiff(frameTexcoordPos, dv), getEyeDepthDiff(frameTexcoordPos, dv));

View file

@ -35,17 +35,11 @@ void main() {
vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVel, sourceColor, historyColor);
vec3 nextColor = sourceColor;
if (taa_constrainColor()) {
// clamp history to neighbourhood of current sample
historyColor = taa_evalConstrainColor(sourceColor, fragUV, fragVel, historyColor);
}
if (taa_feedbackColor()) {
nextColor = taa_evalFeedbackColor(sourceColor, historyColor, params.blend);
} else {
nextColor = mix(historyColor, sourceColor, params.blend);
}
// clamp history to neighbourhood of current sample
historyColor = mix(historyColor, taa_evalConstrainColor(sourceColor, fragUV, fragVel, historyColor), float(taa_constrainColor()));
nextColor = mix(mix(historyColor, sourceColor, params.blend), taa_evalFeedbackColor(sourceColor, historyColor, params.blend), float(taa_feedbackColor()));
outFragColor = vec4(taa_resolveColor(nextColor), 1.0);
}

View file

@ -121,21 +121,17 @@ float taa_fetchDepth(vec2 uv) {
}
#define ZCMP_GT(a, b) (a > b)
#define ZCMP_GT(a, b) float(a > b)
vec2 taa_getImageSize() {
vec2 imageSize = getWidthHeight(0);
if (isStereo()) {
imageSize.x *= 2.0;
}
imageSize.x *= mix(1.0, 2.0, float(isStereo()));
return imageSize;
}
vec2 taa_getTexelSize() {
vec2 texelSize = getInvWidthHeight();
if (isStereo()) {
texelSize.x *= 0.5;
}
texelSize.x *= mix(1.0, 0.5, float(isStereo()));
return texelSize;
}
@ -158,16 +154,16 @@ vec3 taa_findClosestFragment3x3(vec2 uv)
vec3 dbr = vec3( 1, 1, taa_fetchDepth(uv + dv + du));
vec3 dmin = dtl;
if (ZCMP_GT(dmin.z, dtc.z)) dmin = dtc;
if (ZCMP_GT(dmin.z, dtr.z)) dmin = dtr;
dmin = mix(dmin, dtc, ZCMP_GT(dmin.z, dtc.z));
dmin = mix(dmin, dtr, ZCMP_GT(dmin.z, dtr.z));
if (ZCMP_GT(dmin.z, dml.z)) dmin = dml;
if (ZCMP_GT(dmin.z, dmc.z)) dmin = dmc;
if (ZCMP_GT(dmin.z, dmr.z)) dmin = dmr;
dmin = mix(dmin, dml, ZCMP_GT(dmin.z, dml.z));
dmin = mix(dmin, dmc, ZCMP_GT(dmin.z, dmc.z));
dmin = mix(dmin, dmr, ZCMP_GT(dmin.z, dmr.z));
if (ZCMP_GT(dmin.z, dbl.z)) dmin = dbl;
if (ZCMP_GT(dmin.z, dbc.z)) dmin = dbc;
if (ZCMP_GT(dmin.z, dbr.z)) dmin = dbr;
dmin = mix(dmin, dbl, ZCMP_GT(dmin.z, dbl.z));
dmin = mix(dmin, dbc, ZCMP_GT(dmin.z, dbc.z));
dmin = mix(dmin, dbr, ZCMP_GT(dmin.z, dbr.z));
return vec3(uv + dd.xy * dmin.xy, dmin.z);
}
@ -189,49 +185,46 @@ vec2 taa_fetchVelocityMapBest(vec2 uv) {
vec2 dbc = taa_fetchVelocityMap(uv + dv);
vec2 dbr = taa_fetchVelocityMap(uv + dv + du);
vec3 best = vec3(dtl, dot(dtl,dtl));
vec3 best = vec3(dtl, dot(dtl, dtl));
float testSpeed = dot(dtc,dtc);
if (testSpeed > best.z) { best = vec3(dtc, testSpeed); }
testSpeed = dot(dtr,dtr);
if (testSpeed > best.z) { best = vec3(dtr, testSpeed); }
float testSpeed = dot(dtc, dtc);
mix(best, vec3(dtc, testSpeed), float(testSpeed > best.z));
testSpeed = dot(dtr, dtr);
mix(best, vec3(dtr, testSpeed), float(testSpeed > best.z));
testSpeed = dot(dml,dml);
if (testSpeed > best.z) { best = vec3(dml, testSpeed); }
testSpeed = dot(dmc,dmc);
if (testSpeed > best.z) { best = vec3(dmc, testSpeed); }
testSpeed = dot(dmr,dmr);
if (testSpeed > best.z) { best = vec3(dmr, testSpeed); }
testSpeed = dot(dml, dml);
mix(best, vec3(dml, testSpeed), float(testSpeed > best.z));
testSpeed = dot(dmc, dmc);
mix(best, vec3(dmc, testSpeed), float(testSpeed > best.z));
testSpeed = dot(dmr, dmr);
mix(best, vec3(dmr, testSpeed), float(testSpeed > best.z));
testSpeed = dot(dbl,dbl);
if (testSpeed > best.z) { best = vec3(dbl, testSpeed); }
testSpeed = dot(dbc,dbc);
if (testSpeed > best.z) { best = vec3(dbc, testSpeed); }
testSpeed = dot(dbr,dbr);
if (testSpeed > best.z) { best = vec3(dbr, testSpeed); }
testSpeed = dot(dbl, dbl);
mix(best, vec3(dbl, testSpeed), float(testSpeed > best.z));
testSpeed = dot(dbc, dbc);
mix(best, vec3(dbc, testSpeed), float(testSpeed > best.z));
testSpeed = dot(dbr, dbr);
mix(best, vec3(dbr, testSpeed), float(testSpeed > best.z));
return best.xy;
}
vec2 taa_fromFragUVToEyeUVAndSide(vec2 fragUV, out int stereoSide) {
vec2 eyeUV = fragUV;
stereoSide = 0;
if (isStereo()) {
if (eyeUV.x > 0.5) {
eyeUV.x -= 0.5;
stereoSide = 1;
}
eyeUV.x *= 2.0;
}
float check = float(isStereo());
float check2 = float(eyeUV.x > 0.5);
eyeUV.x -= check * check2 * 0.5;
stereoSide = int(check * check2);
eyeUV.x *= mix(1.0, 2.0, check);
return eyeUV;
}
vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) {
vec2 fragUV = eyeUV;
if (isStereo()) {
fragUV.x *= 0.5;
fragUV.x += float(stereoSide)*0.5;
}
float check = float(isStereo());
fragUV.x *= mix(1.0, 0.5, check);
fragUV.x += check * float(stereoSide) * 0.5;
return fragUV;
}
@ -247,10 +240,8 @@ vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceCo
vec2 prevFragUV = taa_computePrevFragAndEyeUV(fragUV, fragVelocity, prevEyeUV);
sourceColor = taa_fetchSourceMap(fragUV).xyz;
historyColor = sourceColor;
if (!(any(lessThan(prevEyeUV, vec2(0.0))) || any(greaterThan(prevEyeUV, vec2(1.0))))) {
historyColor = taa_fetchHistoryMap(prevFragUV).xyz;
}
historyColor = mix(sourceColor, taa_fetchHistoryMap(prevFragUV).xyz, float(!(any(lessThan(prevEyeUV, vec2(0.0))) || any(greaterThan(prevEyeUV, vec2(1.0))))));
return prevFragUV;
}
@ -405,10 +396,11 @@ vec3 taa_clampColor(vec3 colorMin, vec3 colorMax, vec3 colorSource, vec3 color)
vec3 a_unit = abs(v_unit);
float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z));
if (ma_unit > 1.0)
if (ma_unit > 1.0) {
return p_clip + v_clip / ma_unit;
else
return q;// point inside aabb
} else {
return q;// point inside aabb
}
}
vec3 taa_evalConstrainColor(vec3 sourceColor, vec2 sourceUV, vec2 sourceVel, vec3 candidateColor) {
@ -514,10 +506,6 @@ vec3 taa_evalFXAA(vec2 fragUV) {
// compare luma of new samples to the luma range of the original neighborhood
// if the new samples exceed this range, just use the first two samples instead of all four
if (lumaB < lumaMin || lumaB > lumaMax) {
return rgbA;
} else {
return rgbB;
}
return mix(rgbB, rgbA, float(lumaB < lumaMin || lumaB > lumaMax));
}

View file

@ -83,32 +83,21 @@ void main(void) {
if ((prevOrbPosToPixLength < tenPercentHeight) && (cursorVelocityLength > 0.5)) {
vec2 prevOrbPosToPix_uv = cursorPrevUV + prevOrbPosToPix * texelSize / taa_getDebugOrbZoom();
vec3 preOrbColor = vec3(0.0);
if (!(any(lessThan(prevOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(prevOrbPosToPix_uv, vec2(1.0))))) {
preOrbColor = texture(historyMap, prevOrbPosToPix_uv).xyz;
}
if (prevOrbPosToPixLength < orbPixThreshold) {
preOrbColor = vec3(1.0, 0.0, 1.0);
}
preOrbColor = mix(preOrbColor, texture(historyMap, prevOrbPosToPix_uv).xyz, float(!(any(lessThan(prevOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(prevOrbPosToPix_uv, vec2(1.0))))));
preOrbColor = mix(preOrbColor, vec3(1.0, 0.0, 1.0), float(prevOrbPosToPixLength < orbPixThreshold));
float distanceToNext = length(imageSize * (cursorUV - prevOrbPosToPix_uv));
if (distanceToNext < orbPixThreshold) {
preOrbColor = vec3(1.0, 0.5, 0.0);
}
preOrbColor = mix(preOrbColor, vec3(1.0, 0.5, 0.0), float(distanceToNext < orbPixThreshold));
outFragColor = vec4(preOrbColor, 1.0);
return;
}
if (nextOrbPosToPixLength < tenPercentHeight) {
vec2 nextOrbPosToPix_uv = cursorUV + nextOrbPosToPix * texelSize / taa_getDebugOrbZoom();
vec3 nextOrbColor = vec3(0.0);
if (!(any(lessThan(nextOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(nextOrbPosToPix_uv, vec2(1.0))))) {
nextOrbColor = texture(nextMap, nextOrbPosToPix_uv).xyz;
}
nextOrbColor = mix(nextOrbColor, texture(nextMap, nextOrbPosToPix_uv).xyz, float(!(any(lessThan(nextOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(nextOrbPosToPix_uv, vec2(1.0))))));
float distanceToPrev = length(imageSize * (cursorPrevUV - nextOrbPosToPix_uv));
if (distanceToPrev < orbPixThreshold) {
nextOrbColor = vec3(1.0, 0.0, 1.0);
}
if (nextOrbPosToPixLength < orbPixThreshold) {
nextOrbColor = vec3(1.0, 0.5, 0.0);
}
nextOrbColor = mix(nextOrbColor, vec3(1.0, 0.0, 1.0), float(distanceToPrev < orbPixThreshold));
nextOrbColor = mix(nextOrbColor, vec3(1.0, 0.5, 0.0), float(nextOrbPosToPixLength < orbPixThreshold));
outFragColor = vec4(nextOrbColor, 1.0);
return;
@ -141,16 +130,9 @@ void main(void) {
outFragColor = vec4(nextColor, 1.0);
vec3 prevColor = nextColor;
prevColor = mix(prevColor, texture(historyMap, prevTexCoord).xyz, float(!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))));
if (!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))) {
prevColor = texture(historyMap, prevTexCoord).xyz;
}
outFragColor.xyz = mix(prevColor, vec3(1, 0, 1), clamp(distance(prevColor, nextColor) - 0.01, 0.0, 1.0));
outFragColor.xyz = mix(prevColor, vec3(1,0,1), clamp(distance(prevColor, nextColor) - 0.01, 0.0, 1.0));
if (pixVelocityLength > params.debugShowVelocityThreshold) {
vec3 speedColor = taa_getVelocityColorAboveThreshold(pixVelocityLength);
outFragColor = vec4(0.0, 1.0, 1.0, 1.0);
}
outFragColor = mix(outFragColor, vec4(0.0, 1.0, 1.0, 1.0), float(pixVelocityLength > params.debugShowVelocityThreshold));
}

View file

@ -44,7 +44,7 @@ void main(void) {
// vec3 ambient = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(lightAmbient), fragNormal).xyz;
// _fragColor = vec4( 0.5 * (fragNormal + vec3(1.0)), 1.0);
vec3 color = (sphereUV.x > 0.0 ? ambientMap : ambientSH);
vec3 color = mix(ambientSH, ambientMap, float(sphereUV.x > 0.0));
color = color * 1.0 - base.w + base.xyz * base.w;
const float INV_GAMMA_22 = 1.0 / 2.2;

View file

@ -35,16 +35,11 @@ void main(void) {
vec3 color = skybox.color.rgb;
// blend is only set if there is a cubemap
if (skybox.color.a > 0.0) {
color = texture(skyboxMap, direction).rgb;
if (skybox.color.a < 1.0) {
color *= skybox.color.rgb;
}
}
float check = float(skybox.color.a > 0.0);
color = mix(color, texture(skyboxMap, direction).rgb, check);
color *= mix(vec3(1.0), skybox.color.rgb, check * float(skybox.color.a < 1.0));
color = color * 1.0 - base.w + base.xyz * base.w;
const float INV_GAMMA_22 = 1.0 / 2.2;
_fragColor = vec4(pow(color, vec3(INV_GAMMA_22)), 1.0);
}

View file

@ -98,9 +98,10 @@ vec4 pixelShaderGaussian(vec2 texcoord, vec2 direction, vec2 pixelStep) {
totalWeight += weight;
}
}
float check = float(totalWeight > 0.0);
srcBlurred *= check / totalWeight + (1.0 - check);
if (totalWeight > 0.0) {
srcBlurred /= totalWeight;
}
srcBlurred.a = getOutputAlpha();
return srcBlurred;
@ -159,9 +160,10 @@ vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep
totalWeight += weight;
}
}
float check = float(totalWeight > 0.0);
srcBlurred *= check / totalWeight + (1.0 - check);
if (totalWeight > 0.0) {
srcBlurred /= totalWeight;
}
return srcBlurred;
}

View file

@ -51,7 +51,7 @@ void main(void) {
vec4 pos = UNIT_BOX[UNIT_BOX_LINE_INDICES[gl_VertexID]];
int cellIsEmpty = sign(inCellLocation.w);
ivec4 cellLocation = ivec4(inCellLocation.xyz, (inCellLocation.w < 0 ? -inCellLocation.w : inCellLocation.w));
ivec4 cellLocation = ivec4(inCellLocation.xyz, cellIsEmpty * inCellLocation.w);
vec4 cellBound = evalBound(cellLocation);
pos.xyz = cellBound.xyz + vec3(cellBound.w) * pos.xyz;

View file

@ -18,11 +18,7 @@ layout(location=0) out vec4 outFragColor;
void main(void) {
float var = step(fract(varTexcoord.x * varTexcoord.y * 1.0), 0.5);
if (varColor.a == 0.0) {
outFragColor = vec4(mix(vec3(0.0), varColor.xyz, var), mix(0.0, 1.0, var));
} else {
outFragColor = vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a);
}
outFragColor = mix(vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a),
vec4(mix(vec3(0.0), varColor.xyz, var), mix(0.0, 1.0, var)),
float(varColor.a == 0.0));
}

View file

@ -98,11 +98,6 @@ void main(void) {
TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
if (params.color.w < 0.0) {
varColor = vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0);
} else {
varColor = vec4(colorWheel(float(params.color.w)), 1.0);
}
varColor = mix(vec4(colorWheel(float(params.color.w)), 1.0), vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0), float(params.color.w < 0.0));
varTexcoord = vec2(cubeVec.w, length(boundDim));
}

View file

@ -22,10 +22,9 @@ vec2 getIconTexcoord(float icon, vec2 uv) {
}
void main(void) {
if (varTexcoord.z < 254.5) {
outFragColor = texture(_icons, getIconTexcoord(varTexcoord.z, varTexcoord.xy)) * varColor;
} else {
vec2 centerDir = varTexcoord.xy * 2.0f - 1.0f;
outFragColor = vec4(varColor.xyz, 1.0 - step(1.0f, dot(centerDir.xy, centerDir.xy)));
}
vec2 centerDir = varTexcoord.xy * 2.0f - 1.0f;
outFragColor = mix(vec4(varColor.xyz, 1.0 - step(1.0f, dot(centerDir.xy, centerDir.xy))),
texture(_icons, getIconTexcoord(varTexcoord.z, varTexcoord.xy)) * varColor,
float(varTexcoord.z < 254.5));
}