-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy patheffect-f.sdr
More file actions
63 lines (56 loc) · 2.08 KB
/
Copy patheffect-f.sdr
File metadata and controls
63 lines (56 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifdef GL_ES
precision highp float;
precision highp int;
precision highp sampler2D;
precision highp sampler2DArray;
precision highp samplerCube;
#endif
#include "gamma.sdr"
#include "z-compress.sdr"
in float fragRadius;
in vec4 fragPosition;
in vec4 fragTexCoord;
in vec4 fragColor;
layout (location=0) out vec4 fragOut0;
uniform sampler2DArray baseMap;
uniform sampler2D depthMap;
layout (std140) uniform genericData {
float window_width;
float window_height;
float nearZ;
float farZ;
int linear_depth;
int srgb;
int blend_alpha;
};
void main()
{
vec4 fragmentColor = texture(baseMap, fragTexCoord.xyz);
fragmentColor.rgb = mix(fragmentColor.rgb, srgb_to_linear(fragmentColor.rgb), float(srgb));
fragmentColor *= mix(fragColor, vec4(srgb_to_linear(fragColor.rgb), fragColor.a), float(srgb));
vec2 offset = vec2(fragRadius * abs(0.5 - fragTexCoord.x) * 2.0, fragRadius * abs(0.5 - fragTexCoord.y) * 2.0);
float offset_len = length(offset);
if ( offset_len > fragRadius ) {
fragOut0 = vec4(0.0, 0.0, 0.0, 0.0);
return;
}
vec2 depthCoord = vec2(gl_FragCoord.x / window_width, gl_FragCoord.y / window_height );
vec4 sceneDepth = texture(depthMap, depthCoord);
float sceneDepthLinear;
float fragDepthLinear;
if ( linear_depth == 1 ) {
sceneDepthLinear = -uncompress_depth_value(sceneDepth.z);
fragDepthLinear = -fragPosition.z;
} else {
sceneDepthLinear = ( 2.0 * farZ * nearZ ) / ( farZ + nearZ - sceneDepth.x * (farZ-nearZ) );
fragDepthLinear = ( 2.0 * farZ * nearZ ) / ( farZ + nearZ - gl_FragCoord.z * (farZ-nearZ) );
}
// assume UV of 0.5, 0.5 is the centroid of this sphere volume
float depthOffset = sqrt((fragRadius*fragRadius) - (offset_len*offset_len));
float frontDepth = fragDepthLinear - depthOffset;
float backDepth = fragDepthLinear + depthOffset;
float intensity = smoothstep(max(nearZ, frontDepth), backDepth, sceneDepthLinear);
fragmentColor.rgb *= (srgb == 1) ? 1.5 : 1.0;
fragmentColor = (blend_alpha == 1) ? vec4(fragmentColor.rgb, fragmentColor.a * intensity) : vec4(fragmentColor.rgb * intensity, fragmentColor.a);
fragOut0 = max(fragmentColor, vec4(0.0));
}