mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
start removing branching
This commit is contained in:
parent
67fe43ebb1
commit
e8c5324e39
14 changed files with 144 additions and 145 deletions
|
@ -231,7 +231,8 @@ float snoise(vec2 v) {
|
|||
|
||||
// Other corners
|
||||
vec2 i1;
|
||||
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
|
||||
float check = float(x0.x > x0.y);
|
||||
i1 = vec2(check, 1.0 - check);
|
||||
vec4 x12 = x0.xyxy + C.xxzz;
|
||||
x12.xy -= i1;
|
||||
|
||||
|
|
|
@ -151,29 +151,37 @@ float fetchScatteringMap(vec2 uv) {
|
|||
|
||||
|
||||
<@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, scattering)@>
|
||||
float check;
|
||||
<@if albedo@>
|
||||
vec4 <$albedo$> = (((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0));
|
||||
check = float((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0);
|
||||
vec4 <$albedo$> = check * fetchAlbedoMap(<$texcoord0$>) + vec4(1.0 - check);
|
||||
<@endif@>
|
||||
<@if roughness@>
|
||||
float <$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? fetchRoughnessMap(<$texcoord0$>) : 1.0);
|
||||
check = float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0);
|
||||
float <$roughness$> = check * fetchRoughnessMap(<$texcoord0$>) + (1.0 - check);
|
||||
<@endif@>
|
||||
<@if normal@>
|
||||
vec3 <$normal$> = (((<$matKey$> & NORMAL_MAP_BIT) != 0) ? fetchNormalMap(<$texcoord0$>) : vec3(0.0, 1.0, 0.0));
|
||||
check = float((<$matKey$> & NORMAL_MAP_BIT) != 0);
|
||||
vec3 <$normal$> = check * fetchNormalMap(<$texcoord0$>) + vec3(0.0, 1.0 - check, 0.0);
|
||||
<@endif@>
|
||||
<@if metallic@>
|
||||
float <$metallic$> = (((<$matKey$> & METALLIC_MAP_BIT) != 0) ? fetchMetallicMap(<$texcoord0$>) : 0.0);
|
||||
check = float((<$matKey$> & METALLIC_MAP_BIT) != 0);
|
||||
float <$metallic$> = check * fetchMetallicMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@if emissive@>
|
||||
vec3 <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? fetchEmissiveMap(<$texcoord0$>) : vec3(0.0));
|
||||
check = float((<$matKey$> & EMISSIVE_MAP_BIT) != 0);
|
||||
vec3 <$emissive$> = check * fetchEmissiveMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@if scattering@>
|
||||
float <$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? fetchScatteringMap(<$texcoord0$>) : 0.0);
|
||||
check = float((<$matKey$> & SCATTERING_MAP_BIT) != 0);
|
||||
float <$scattering$> = check * fetchScatteringMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@endfunc@>
|
||||
|
||||
<@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmapVal)@>
|
||||
<@if occlusion@>
|
||||
float <$occlusion$> = (((<$matKey$> & OCCLUSION_MAP_BIT) != 0) ? fetchOcclusionMap(<$texcoord1$>) : 1.0);
|
||||
float check1 = float((<$matKey$> & OCCLUSION_MAP_BIT) != 0);
|
||||
float <$occlusion$> = check1 * fetchOcclusionMap(<$texcoord1$>) + (1.0 - check1);
|
||||
<@endif@>
|
||||
<@if lightmapVal@>
|
||||
vec3 <$lightmapVal$> = fetchLightmapMap(<$texcoord1$>);
|
||||
|
@ -217,20 +225,20 @@ vec3 fetchLightmapMap(vec2 uv) {
|
|||
|
||||
<@func evalMaterialAlbedo(fetchedAlbedo, materialAlbedo, matKey, albedo)@>
|
||||
{
|
||||
<$albedo$>.xyz = (((<$matKey$> & ALBEDO_VAL_BIT) != 0) ? <$materialAlbedo$> : vec3(1.0));
|
||||
float check = float((<$matKey$> & ALBEDO_VAL_BIT) != 0);
|
||||
<$albedo$>.xyz = check * <$materialAlbedo$> + vec3(1.0 - check);
|
||||
|
||||
if (((<$matKey$> & ALBEDO_MAP_BIT) != 0)) {
|
||||
<$albedo$>.xyz *= <$fetchedAlbedo$>.xyz;
|
||||
}
|
||||
check = float((<$matKey$> & ALBEDO_MAP_BIT) != 0);
|
||||
<$albedo$>.xyz *= check * <$fetchedAlbedo$>.xyz + vec3(1.0 - check);
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func evalMaterialOpacity(fetchedOpacity, materialOpacity, matKey, opacity)@>
|
||||
{
|
||||
const float OPACITY_MASK_THRESHOLD = 0.5;
|
||||
<$opacity$> = (((<$matKey$> & (OPACITY_TRANSLUCENT_MAP_BIT | OPACITY_MASK_MAP_BIT)) != 0) ?
|
||||
(((<$matKey$> & OPACITY_MASK_MAP_BIT) != 0) ? step(OPACITY_MASK_THRESHOLD, <$fetchedOpacity$>) : <$fetchedOpacity$>) :
|
||||
1.0) * <$materialOpacity$>;
|
||||
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$>;
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
|
@ -251,19 +259,22 @@ vec3 fetchLightmapMap(vec2 uv) {
|
|||
|
||||
<@func evalMaterialRoughness(fetchedRoughness, materialRoughness, matKey, roughness)@>
|
||||
{
|
||||
<$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? <$fetchedRoughness$> : <$materialRoughness$>);
|
||||
float check = float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0);
|
||||
<$roughness$> = check * <$fetchedRoughness$> + (1.0 - check) * <$materialRoughness$>;
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func evalMaterialMetallic(fetchedMetallic, materialMetallic, matKey, metallic)@>
|
||||
{
|
||||
<$metallic$> = (((<$matKey$> & METALLIC_MAP_BIT) != 0) ? <$fetchedMetallic$> : <$materialMetallic$>);
|
||||
float check = float((<$matKey$> & METALLIC_MAP_BIT) != 0);
|
||||
<$metallic$> = check * <$fetchedMetallic$> + (1.0 - check) * <$materialMetallic$>;
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func evalMaterialEmissive(fetchedEmissive, materialEmissive, matKey, emissive)@>
|
||||
{
|
||||
<$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? <$fetchedEmissive$> : <$materialEmissive$>);
|
||||
float check = float((<$matKey$> & EMISSIVE_MAP_BIT) != 0);
|
||||
<$emissive$> = check * <$fetchedEmissive$> + (1.0 - check) * <$materialEmissive$>;
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
|
@ -275,7 +286,8 @@ vec3 fetchLightmapMap(vec2 uv) {
|
|||
|
||||
<@func evalMaterialScattering(fetchedScattering, materialScattering, matKey, scattering)@>
|
||||
{
|
||||
<$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? <$fetchedScattering$> : <$materialScattering$>);
|
||||
float check = float((<$matKey$> & SCATTERING_MAP_BIT) != 0);
|
||||
<$scattering$> = check * <$fetchedScattering$> + (1.0 - check) * <$materialScattering$>;
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
|
|
|
@ -76,14 +76,12 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
|
|||
|
||||
// Diffuse color and unpack the mode and the metallicness
|
||||
frag.albedo = diffuseVal.xyz;
|
||||
frag.scattering = 0.0;
|
||||
unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic);
|
||||
|
||||
frag.obscurance = min(specularVal.w, frag.obscurance);
|
||||
|
||||
if (frag.mode == FRAG_MODE_SCATTERING) {
|
||||
frag.scattering = specularVal.x;
|
||||
}
|
||||
float check = float(frag.mode == FRAG_MODE_SCATTERING);
|
||||
frag.scattering = check * specularVal.x;
|
||||
|
||||
frag.fresnel = getFresnelF0(frag.metallic, diffuseVal.xyz);
|
||||
|
||||
|
@ -122,14 +120,11 @@ DeferredFragment unpackDeferredFragmentNoPositionNoAmbient(vec2 texcoord) {
|
|||
<$declareDeferredFrameTransform()$>
|
||||
|
||||
vec4 unpackDeferredPosition(float depthValue, vec2 texcoord) {
|
||||
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 = 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;
|
||||
|
||||
return vec4(evalEyePositionFromZdb(side, depthValue, texcoord), 1.0);
|
||||
}
|
||||
|
@ -142,19 +137,15 @@ vec4 unpackDeferredPositionFromZdb(vec2 texcoord) {
|
|||
|
||||
vec4 unpackDeferredPositionFromZeye(vec2 texcoord) {
|
||||
float Zeye = -texture(linearZeyeMap, 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 = 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;
|
||||
return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0);
|
||||
}
|
||||
|
||||
DeferredFragment unpackDeferredFragment(DeferredFrameTransform deferredTransform, vec2 texcoord) {
|
||||
|
||||
float depthValue = texture(depthMap, texcoord).r;
|
||||
|
||||
DeferredFragment frag = unpackDeferredFragmentNoPosition(texcoord);
|
||||
|
|
|
@ -32,9 +32,11 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness
|
|||
if (alpha != 1.0) {
|
||||
discard;
|
||||
}
|
||||
_fragColor0 = vec4(albedo, ((scattering > 0.0) ? packScatteringMetallic(metallic) : packShadedMetallic(metallic)));
|
||||
|
||||
float check = float(scattering > 0.0);
|
||||
_fragColor0 = vec4(albedo, check * packScatteringMetallic(metallic) + (1.0 - check) * packShadedMetallic(metallic));
|
||||
_fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0));
|
||||
_fragColor2 = vec4(((scattering > 0.0) ? vec3(scattering) : emissive), occlusion);
|
||||
_fragColor2 = vec4(check * vec3(scattering) + (1.0 - check) * emissive, occlusion);
|
||||
|
||||
_fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0);
|
||||
}
|
||||
|
|
|
@ -126,7 +126,8 @@ vec2 getSideImageSize(int resolutionLevel) {
|
|||
|
||||
ivec4 getStereoSideInfo(int xPos, int resolutionLevel) {
|
||||
int sideWidth = int(getStereoSideWidth(resolutionLevel));
|
||||
return ivec4(xPos < sideWidth ? ivec2(0, 0) : ivec2(1, sideWidth), sideWidth, isStereo());
|
||||
int check = int(xPos < sideWidth);
|
||||
return ivec4((1 - check) * ivec2(1, sideWidth), sideWidth, isStereo());
|
||||
}
|
||||
|
||||
float evalZeyeFromZdb(float depth) {
|
||||
|
|
|
@ -85,7 +85,12 @@ float evalFadeGradient(FadeObjectParams params, vec3 position) {
|
|||
}
|
||||
|
||||
float evalFadeAlpha(FadeObjectParams params, vec3 position) {
|
||||
return evalFadeGradient(params, position)-params.threshold;
|
||||
float alpha = evalFadeGradient(params, position) - params.threshold;
|
||||
|
||||
float check = float(fadeParameters[params.category]._isInverted != 0);
|
||||
alpha *= -check + (1.0 - check);
|
||||
|
||||
return alpha;
|
||||
}
|
||||
|
||||
void applyFadeClip(FadeObjectParams params, vec3 position) {
|
||||
|
@ -96,9 +101,6 @@ void applyFadeClip(FadeObjectParams params, vec3 position) {
|
|||
|
||||
void applyFade(FadeObjectParams params, vec3 position, out vec3 emissive) {
|
||||
float alpha = evalFadeAlpha(params, position);
|
||||
if (fadeParameters[params.category]._isInverted!=0) {
|
||||
alpha = -alpha;
|
||||
}
|
||||
|
||||
if (alpha < 0.0) {
|
||||
discard;
|
||||
|
|
|
@ -63,20 +63,18 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirectionWS, vec3
|
|||
// Height at which haze density is reduced by 95% (default set to 2000.0 for safety ,this should never happen)
|
||||
float height_95p = 2000.0;
|
||||
const float log_p_005 = log(0.05);
|
||||
if (hazeParams.hazeKeyLightAltitudeFactor > 0.0f) {
|
||||
height_95p = -log_p_005 / hazeParams.hazeKeyLightAltitudeFactor;
|
||||
|
||||
{
|
||||
float check = float(hazeParams.hazeKeyLightAltitudeFactor > 0.0f);
|
||||
height_95p = check * -log_p_005 / hazeParams.hazeKeyLightAltitudeFactor + (1.0 - check) * height_95p;
|
||||
}
|
||||
|
||||
// Note that we need the sine to be positive
|
||||
float sin_pitch = abs(lightDirectionWS.y);
|
||||
|
||||
float distance;
|
||||
const float minimumSinPitch = 0.001;
|
||||
if (sin_pitch < minimumSinPitch) {
|
||||
distance = height_95p / minimumSinPitch;
|
||||
} else {
|
||||
distance = height_95p / sin_pitch;
|
||||
}
|
||||
float sin_pitch = abs(lightDirectionWS.y);
|
||||
sin_pitch = max(sin_pitch, minimumSinPitch);
|
||||
|
||||
float distance = height_95p / sin_pitch;
|
||||
|
||||
// Integration is from the fragment towards the light source
|
||||
// Note that the haze base reference affects only the haze density as function of altitude
|
||||
|
@ -128,6 +126,7 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition
|
|||
}
|
||||
|
||||
vec4 potentialFragColor;
|
||||
const float EPSILON = 0.0000001f;
|
||||
|
||||
if ((hazeParams.hazeMode & HAZE_MODE_IS_MODULATE_COLOR) == HAZE_MODE_IS_MODULATE_COLOR) {
|
||||
// Compute separately for each colour
|
||||
|
@ -143,9 +142,10 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition
|
|||
|
||||
const float slopeThreshold = 0.01;
|
||||
float deltaHeight = fragPositionWS.y - eyeWorldHeight;
|
||||
if (abs(deltaHeight) > slopeThreshold) {
|
||||
float t = hazeParams.hazeHeightFactor * deltaHeight;
|
||||
hazeIntegral *= (1.0 - exp (-t)) / t;
|
||||
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);
|
||||
}
|
||||
|
||||
vec3 hazeAmount = 1.0 - exp(-hazeIntegral);
|
||||
|
@ -171,13 +171,10 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition
|
|||
|
||||
const float slopeThreshold = 0.01;
|
||||
float deltaHeight = fragPositionWS.y - eyeWorldHeight;
|
||||
if (abs(deltaHeight) > slopeThreshold) {
|
||||
float t = hazeParams.hazeHeightFactor * deltaHeight;
|
||||
// Protect from wild values
|
||||
const float EPSILON = 0.0000001f;
|
||||
if (abs(t) > EPSILON) {
|
||||
hazeIntegral *= (1.0 - exp (-t)) / t;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
float hazeAmount = 1.0 - exp(-hazeIntegral);
|
||||
|
@ -189,9 +186,8 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition
|
|||
// Mix with background at far range
|
||||
const float BLEND_DISTANCE = 27000.0f;
|
||||
vec4 outFragColor = potentialFragColor;
|
||||
if (distance > BLEND_DISTANCE) {
|
||||
outFragColor.a *= hazeParams.backgroundBlend;
|
||||
}
|
||||
float check = float(distance > BLEND_DISTANCE);
|
||||
outFragColor.a *= check * hazeParams.backgroundBlend + (1.0 - check);
|
||||
|
||||
return outFragColor;
|
||||
}
|
||||
|
|
|
@ -45,11 +45,9 @@ void main(void) {
|
|||
highlightedDepth = -evalZeyeFromZdb(highlightedDepth);
|
||||
sceneDepth = -evalZeyeFromZdb(sceneDepth);
|
||||
|
||||
if (sceneDepth < highlightedDepth) {
|
||||
outFragColor = vec4(params._fillOccludedColor, params._fillOccludedAlpha);
|
||||
} else {
|
||||
outFragColor = vec4(params._fillUnoccludedColor, params._fillUnoccludedAlpha);
|
||||
}
|
||||
float check = float(sceneDepth < highlightedDepth);
|
||||
outFragColor = check * vec4(params._fillOccludedColor, params._fillOccludedAlpha) +
|
||||
(1.0 - check) * vec4(params._fillUnoccludedColor, params._fillUnoccludedAlpha);
|
||||
<@else@>
|
||||
discard;
|
||||
<@endif@>
|
||||
|
@ -67,14 +65,13 @@ void main(void) {
|
|||
float outlinedDepth = 0.0;
|
||||
float sumOutlineDepth = 0.0;
|
||||
|
||||
for (y=0 ; y<params._blurKernelSize ; y++) {
|
||||
for (y = 0; y < params._blurKernelSize; y++) {
|
||||
uv = lineStartUv;
|
||||
lineStartUv.y += deltaUv.y;
|
||||
|
||||
if (uv.y>=0.0 && uv.y<=1.0) {
|
||||
for (x=0 ; x<params._blurKernelSize ; x++) {
|
||||
if (uv.x>=0.0 && uv.x<=1.0)
|
||||
{
|
||||
if (uv.y >= 0.0 && uv.y <= 1.0) {
|
||||
for (x = 0; x < params._blurKernelSize; x++) {
|
||||
if (uv.x >= 0.0 && uv.x <= 1.0) {
|
||||
outlinedDepth = texture(highlightedDepthMap, uv).x;
|
||||
float touch = (outlinedDepth < FAR_Z) ? 1.0 : 0.0;
|
||||
sumOutlineDepth = max(outlinedDepth * touch, sumOutlineDepth);
|
||||
|
@ -86,10 +83,9 @@ void main(void) {
|
|||
}
|
||||
}
|
||||
|
||||
if (intensity > 0.0) {
|
||||
// sumOutlineDepth /= intensity;
|
||||
} else {
|
||||
sumOutlineDepth = FAR_Z;
|
||||
{
|
||||
float check = float(intensity > 0.0);
|
||||
sumOutlineDepth = check * sumOutlineDepth + (1.0 - check) * FAR_Z;
|
||||
}
|
||||
|
||||
intensity /= weight;
|
||||
|
@ -106,10 +102,10 @@ void main(void) {
|
|||
sceneDepth = -evalZeyeFromZdb(sceneDepth);
|
||||
|
||||
// Are we occluded?
|
||||
if (sceneDepth < outlinedDepth) {
|
||||
outFragColor = vec4(params._outlineOccludedColor, intensity * params._outlineOccludedAlpha);
|
||||
} else {
|
||||
outFragColor = vec4(params._outlineUnoccludedColor, intensity * params._outlineUnoccludedAlpha);
|
||||
{
|
||||
float check = float(sceneDepth < outlinedDepth);
|
||||
outFragColor = check * vec4(params._outlineOccludedColor, intensity * params._outlineOccludedAlpha) +
|
||||
(1.0 - check) * vec4(params._outlineUnoccludedColor, intensity * params._outlineUnoccludedAlpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,8 @@ int clusterGrid_getClusterLightId(int index, int offset) {
|
|||
return element;
|
||||
*/
|
||||
int element = _clusterGridContent[GRID_FETCH_BUFFER((elementIndex >> 1))];
|
||||
return (((elementIndex & 0x00000001) == 1) ? (element >> 16) : element) & 0x0000FFFF;
|
||||
int check = int((elementIndex & 0x00000001) == 1);
|
||||
return (check * (element >> 16) + (1 - check) * element) & 0x0000FFFF;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,12 @@
|
|||
#define float_exp2 exp2
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define _MIN glm::min
|
||||
#else
|
||||
# define _MIN min
|
||||
#endif
|
||||
|
||||
float frustumGrid_depthRampGridToVolume(float ngrid) {
|
||||
// return ngrid;
|
||||
// return sqrt(ngrid);
|
||||
|
@ -87,14 +93,9 @@ ivec3 frustumGrid_indexToCluster(int index) {
|
|||
}
|
||||
|
||||
vec3 frustumGrid_clusterPosToEye(vec3 clusterPos) {
|
||||
|
||||
vec3 cvpos = clusterPos;
|
||||
|
||||
|
||||
vec3 volumePos = frustumGrid_gridToVolume(cvpos, frustumGrid.dims);
|
||||
|
||||
vec3 eyePos = frustumGrid_volumeToEye(volumePos, frustumGrid.eyeToGridProj, frustumGrid.rangeNear, frustumGrid.rangeFar);
|
||||
|
||||
return eyePos;
|
||||
}
|
||||
|
||||
|
@ -116,27 +117,19 @@ int frustumGrid_eyeDepthToClusterLayer(float eyeZ) {
|
|||
|
||||
int gridZ = int(frustumGrid_volumeToGridDepth(volumeZ, frustumGrid.dims));
|
||||
|
||||
if (gridZ >= frustumGrid.dims.z) {
|
||||
gridZ = frustumGrid.dims.z;
|
||||
}
|
||||
|
||||
|
||||
return gridZ;
|
||||
return _MIN(gridZ, frustumGrid.dims.z);
|
||||
}
|
||||
|
||||
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 = (eyePos.z > 0.0f ? -eyePos.z : eyePos.z);
|
||||
frontEyePos.z = -abs(eyePos.z);
|
||||
vec3 volumePos = frustumGrid_eyeToVolume(frontEyePos, frustumGrid.eyeToGridProj, frustumGrid.rangeNear, frustumGrid.rangeFar);
|
||||
|
||||
|
||||
vec3 gridPos = frustumGrid_volumeToGrid(volumePos, frustumGrid.dims);
|
||||
|
||||
if (gridPos.z >= float(frustumGrid.dims.z)) {
|
||||
gridPos.z = float(frustumGrid.dims.z);
|
||||
}
|
||||
gridPos.z = _MIN(gridPos.z, float(frustumGrid.dims.z));
|
||||
|
||||
ivec3 igridPos = ivec3(floor(gridPos));
|
||||
|
||||
|
@ -154,7 +147,8 @@ ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) {
|
|||
|
||||
int frustumGrid_eyeToClusterDirH(vec3 eyeDir) {
|
||||
if (eyeDir.z >= 0.0f) {
|
||||
return (eyeDir.x > 0.0f ? frustumGrid.dims.x : -1);
|
||||
int check = int(eyeDir.x > 0.0f);
|
||||
return check * frustumGrid.dims.x + (check - 1);
|
||||
}
|
||||
|
||||
float eyeDepth = -eyeDir.z;
|
||||
|
@ -168,7 +162,8 @@ int frustumGrid_eyeToClusterDirH(vec3 eyeDir) {
|
|||
|
||||
int frustumGrid_eyeToClusterDirV(vec3 eyeDir) {
|
||||
if (eyeDir.z >= 0.0f) {
|
||||
return (eyeDir.y > 0.0f ? frustumGrid.dims.y : -1);
|
||||
int check = int(eyeDir.y > 0.0f);
|
||||
return check * frustumGrid.dims.y + (check - 1);
|
||||
}
|
||||
|
||||
float eyeDepth = -eyeDir.z;
|
||||
|
|
|
@ -39,14 +39,13 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light,
|
|||
lightEnergy *= isPointEnabled();
|
||||
diffuse *= lightEnergy * isDiffuseEnabled();
|
||||
specular *= lightEnergy * isSpecularEnabled();
|
||||
|
||||
if (isShowLightContour() > 0.0) {
|
||||
// Show edge
|
||||
|
||||
{
|
||||
// Show edges
|
||||
float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0);
|
||||
if (edge < 1.0) {
|
||||
float edgeCoord = exp2(-8.0*edge*edge);
|
||||
diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light));
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,12 +58,13 @@ bool evalLightPointEdge(out vec3 color, Light light, vec4 fragLightDirLen, vec3
|
|||
// Allright we re valid in the volume
|
||||
float fragLightDistance = fragLightDirLen.w;
|
||||
vec3 fragLightDir = fragLightDirLen.xyz;
|
||||
|
||||
// Show edges
|
||||
|
||||
float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0);
|
||||
if (edge < 1.0) {
|
||||
float edgeCoord = exp2(-8.0*edge*edge);
|
||||
color = vec3(edgeCoord * edgeCoord * getLightColor(light));
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
return (edge < 1.0);
|
||||
|
|
|
@ -40,17 +40,16 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light,
|
|||
lightEnergy *= isSpotEnabled();
|
||||
diffuse *= lightEnergy * isDiffuseEnabled();
|
||||
specular *= lightEnergy * isSpecularEnabled();
|
||||
|
||||
if (isShowLightContour() > 0.0) {
|
||||
|
||||
{
|
||||
// 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);
|
||||
if (edge < 1.0) {
|
||||
float edgeCoord = exp2(-8.0*edge*edge);
|
||||
diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light));
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,19 +62,18 @@ 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);
|
||||
if (edge < 1.0) {
|
||||
float edgeCoord = exp2(-8.0*edge*edge);
|
||||
color = vec3(edgeCoord * edgeCoord * getLightColor(light));
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
return (edge < 1.0);
|
||||
}
|
||||
|
||||
<@endfunc@>
|
||||
|
||||
|
||||
|
|
|
@ -115,17 +115,21 @@ float evalShadowAttenuation(vec3 worldLightDir, vec4 worldPosition, float viewDe
|
|||
isPixelOnCascade.z = isShadowCascadeProjectedOnPixel(cascadeShadowCoords[2]);
|
||||
isPixelOnCascade.w = isShadowCascadeProjectedOnPixel(cascadeShadowCoords[3]);
|
||||
|
||||
if (isPixelOnCascade.x) {
|
||||
cascadeAttenuations.x = evalShadowCascadeAttenuation(0, offsets, cascadeShadowCoords[0], oneMinusNdotL);
|
||||
{
|
||||
float check = float(isPixelOnCascade.x);
|
||||
cascadeAttenuations.x = check * evalShadowCascadeAttenuation(0, offsets, cascadeShadowCoords[0], oneMinusNdotL) + (1.0 - check);
|
||||
}
|
||||
if (isPixelOnCascade.y) {
|
||||
cascadeAttenuations.y = evalShadowCascadeAttenuation(1, offsets, cascadeShadowCoords[1], oneMinusNdotL);
|
||||
{
|
||||
float check = float(isPixelOnCascade.y);
|
||||
cascadeAttenuations.y = check * evalShadowCascadeAttenuation(1, offsets, cascadeShadowCoords[1], oneMinusNdotL) + (1.0 - check);
|
||||
}
|
||||
if (isPixelOnCascade.z) {
|
||||
cascadeAttenuations.z = evalShadowCascadeAttenuation(2, offsets, cascadeShadowCoords[2], oneMinusNdotL);
|
||||
{
|
||||
float check = float(isPixelOnCascade.z);
|
||||
cascadeAttenuations.z = check * evalShadowCascadeAttenuation(2, offsets, cascadeShadowCoords[2], oneMinusNdotL) + (1.0 - check);
|
||||
}
|
||||
if (isPixelOnCascade.w) {
|
||||
cascadeAttenuations.w = evalShadowCascadeAttenuation(3, offsets, cascadeShadowCoords[3], oneMinusNdotL);
|
||||
{
|
||||
float check = float(isPixelOnCascade.w);
|
||||
cascadeAttenuations.w = check * evalShadowCascadeAttenuation(3, offsets, cascadeShadowCoords[3], oneMinusNdotL) + (1.0 - check);
|
||||
}
|
||||
|
||||
cascadeWeights.x = evalShadowCascadeWeight(cascadeShadowCoords[0]);
|
||||
|
|
|
@ -99,9 +99,9 @@ vec4 pixelShaderGaussian(vec2 texcoord, vec2 direction, vec2 pixelStep) {
|
|||
}
|
||||
}
|
||||
|
||||
if (totalWeight>0.0) {
|
||||
srcBlurred /= totalWeight;
|
||||
}
|
||||
float check = float(totalWeight > 0.0);
|
||||
srcBlurred *= check / totalWeight + (1.0 - check);
|
||||
|
||||
srcBlurred.a = getOutputAlpha();
|
||||
return srcBlurred;
|
||||
}
|
||||
|
@ -160,9 +160,9 @@ vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep
|
|||
}
|
||||
}
|
||||
|
||||
if (totalWeight>0.0) {
|
||||
srcBlurred /= totalWeight;
|
||||
}
|
||||
float check = float(totalWeight > 0.0);
|
||||
srcBlurred *= check / totalWeight + (1.0 - check);
|
||||
|
||||
return srcBlurred;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue