Skip to content

Commit 2ca7268

Browse files
committed
Update PSF core
1 parent b2d23fb commit 2ca7268

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

shaders/star_frag.glsl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@ varying vec3 v_color;
88
varying float max_theta;
99
varying float pointSize;
1010

11-
float psf_central(float offset)
11+
float psf_core(float offset)
1212
{
13-
// Human eye's point source function from the research by Greg Spencer et al.
14-
// Optimized for the central part of the PSF. The flow from the four neighboring pixels is constant.
13+
// Human eye's point source function from the research by Greg Spencer et al. (1995)
14+
// Optimized for the central part of the PSF. The flow from the nine neighboring pixels is constant.
1515
// Designed for degree_per_px == 0.01.
16-
if (offset < 1.6667)
17-
{
18-
return 1.0 + 1.136 * offset * (0.3 * offset - 1.0);
19-
}
20-
return 0.0; // function starts to grow again
16+
return 1.0 + offset * (0.2789 * offset - 1.0);
17+
// the second summand is allowed to be scaled to achieve a seamless transition between modes
2118
}
2219

23-
float psf_outer(float offset)
20+
float psf_glow(float offset)
2421
{
25-
// Human eye's point source function from the research by Greg Spencer et al.
22+
// Human eye's point source function from the research by Greg Spencer et al. (1995)
2623
// Optimized for the outer part of the PSF. Designed with bounds by arctangent in mind.
2724
// Causes star blinking with degree_per_px > 0.01, large grid misses the center peak of brightness.
2825
float theta = offset * degree_per_px;
@@ -40,7 +37,6 @@ void main(void)
4037
{
4138
// in fragment shader all points have virtual dimension 1x1, so gl_PointCoord has a value from [0; 1]
4239
float offset = length((gl_PointCoord.xy - vec2(0.5)) * pointSize);
43-
float glow_bw = (max_theta == -1.0) ? psf_central(offset) : psf_outer(offset);
44-
vec3 glow_colored = v_color * glow_bw; // color and brightness scaling
45-
gl_FragColor = vec4(glow_colored, 1.0)+ vec4(0.1, 0.0, 0.0, 0.0);
40+
float black_and_white = (max_theta == -1.0) ? psf_core(offset) : psf_glow(offset);
41+
gl_FragColor = vec4(v_color * black_and_white, 1.0); // + vec4(0.1, 0.0, 0.0, 0.0); // square for debugging
4642
}

shaders/star_vert.glsl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ void main(void)
4747
//if (max(scaled_color.r, max(scaled_color.g, scaled_color.b)) < 1.0)
4848
//if (true)
4949
{
50-
// Option 1: Weak light source, no glow
51-
// use max_theta == -1 as an indicator
52-
max_theta = -1.0;
50+
// Dim light source (9 pixels mode)
51+
max_theta = -1.0; // mode indicator
5352
pointSize = 3.0;
5453
v_color = scaled_color;
5554
}
5655
else
5756
{
58-
// Option 2: Strong light source, glow
57+
// Bright light source (glow mode)
5958
br = atan(br0 / max_br) * max_br; // dimmed brightness
6059
max_theta = a * sqrt(br); // glow radius
6160
float half_sq = max_theta / degree_per_px;

0 commit comments

Comments
 (0)