Skip to content

Commit

Permalink
Update PSF core
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaniy committed Jul 2, 2024
1 parent b2d23fb commit 2ca7268
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
22 changes: 9 additions & 13 deletions shaders/star_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ varying vec3 v_color;
varying float max_theta;
varying float pointSize;

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

float psf_outer(float offset)
float psf_glow(float offset)
{
// Human eye's point source function from the research by Greg Spencer et al.
// Human eye's point source function from the research by Greg Spencer et al. (1995)
// Optimized for the outer part of the PSF. Designed with bounds by arctangent in mind.
// Causes star blinking with degree_per_px > 0.01, large grid misses the center peak of brightness.
float theta = offset * degree_per_px;
Expand All @@ -40,7 +37,6 @@ void main(void)
{
// in fragment shader all points have virtual dimension 1x1, so gl_PointCoord has a value from [0; 1]
float offset = length((gl_PointCoord.xy - vec2(0.5)) * pointSize);
float glow_bw = (max_theta == -1.0) ? psf_central(offset) : psf_outer(offset);
vec3 glow_colored = v_color * glow_bw; // color and brightness scaling
gl_FragColor = vec4(glow_colored, 1.0)+ vec4(0.1, 0.0, 0.0, 0.0);
float black_and_white = (max_theta == -1.0) ? psf_core(offset) : psf_glow(offset);
gl_FragColor = vec4(v_color * black_and_white, 1.0); // + vec4(0.1, 0.0, 0.0, 0.0); // square for debugging
}
7 changes: 3 additions & 4 deletions shaders/star_vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ void main(void)
//if (max(scaled_color.r, max(scaled_color.g, scaled_color.b)) < 1.0)
//if (true)
{
// Option 1: Weak light source, no glow
// use max_theta == -1 as an indicator
max_theta = -1.0;
// Dim light source (9 pixels mode)
max_theta = -1.0; // mode indicator
pointSize = 3.0;
v_color = scaled_color;
}
else
{
// Option 2: Strong light source, glow
// Bright light source (glow mode)
br = atan(br0 / max_br) * max_br; // dimmed brightness
max_theta = a * sqrt(br); // glow radius
float half_sq = max_theta / degree_per_px;
Expand Down

0 comments on commit 2ca7268

Please sign in to comment.