Skip to content

Commit c16c37c

Browse files
committed
wip
1 parent 791a109 commit c16c37c

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

shaders/star_frag.glsl

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const float degree_per_px = 0.05;
22
const float br_limit = 1.0 / (255.0 * 12.92);
33

44
varying vec3 v_color;
5-
varying vec3 v_max_tetha_hk;
5+
varying vec3 v_tetha_k;
66
varying float pointSize;
77

8-
float psf_square(float theta, float min_theta, float max_theta, float h, float k, float b)
8+
float psf_square(float theta, float min_theta, float max_theta, float k)
99
{
1010
// Human eye's point source function, optimized to fit a square.
1111
// Lower limit on brightness and angular size: 1 Vega and 0.05 degrees per pixel.
@@ -16,44 +16,28 @@ float psf_square(float theta, float min_theta, float max_theta, float h, float k
1616

1717
if (theta < max_theta)
1818
{
19-
float brackets = b / (theta - h) - 1.0;
20-
return brackets * brackets / k;
19+
float brackets = max_theta / theta - 1.0;
20+
return k * brackets * brackets;
2121
}
2222

23-
return 0.0; // after max_theta function starts to grow again
23+
return 0.0;
2424
}
2525

26-
/*
27-
float psf_fullscreen(float theta, float min_theta):
28-
{
29-
// Human eye's point source function, optimized to be a full-screen shader.
30-
// The price to pay for simplification is a brightness reduction compared to the original PSF.
31-
32-
if (theta2 < min_theta)
33-
return 1; // overexposed
34-
35-
return 4.43366571e-6 / theta;
36-
}
37-
*/
38-
3926
void main(void)
4027
{
41-
float max_theta = v_max_tetha_hk.x;
28+
float max_theta = v_tetha_k.x;
4229
if (max_theta == -1.0)
4330
{
4431
gl_FragColor = vec4(v_color, 1.0);
4532
}
4633
else
4734
{
48-
float h = v_max_tetha_hk.y;
49-
float k = v_max_tetha_hk.z;
50-
51-
float b = max_theta - h;
52-
float min_theta = h + b / (sqrt(k) + 1.0);
53-
35+
float min_theta = v_tetha_k.y;
36+
float k = v_tetha_k.z;
37+
// Option 2: glare square render
5438
vec2 offset = (gl_PointCoord.xy - vec2(0.5)) * pointSize;
55-
float theta = length(offset) * degree_per_px;
39+
float theta = length(offset) * degree_per_px;
5640

57-
gl_FragColor = vec4(v_color * psf_square(theta, min_theta, max_theta, h, k, b), 1.0);
41+
gl_FragColor = vec4(v_color * psf_square(theta, min_theta, max_theta, k), 1.0);
5842
}
5943
}

shaders/star_vert.glsl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const float degree_per_px = 0.05;
33
const float br_limit = 1.0 / (255.0 * 12.92);
44

55
varying vec3 v_color; // 12
6-
varying vec3 v_max_tetha_hk; // 24
6+
varying vec3 v_tetha_k; // 24
77
varying float pointSize; // 28
88

99
uniform vec2 viewportSize;
@@ -23,16 +23,16 @@ void main(void)
2323
if (check == 0.0)
2424
{
2525
pointSize = 1.0;
26-
v_max_tetha_hk = vec3(-1.0);
26+
v_tetha_k = vec3(-1.0);
2727
}
2828
else
2929
{
30-
float max_theta = 0.33435822702992773 * sqrt(max(color0.r, max(color0.g, color0.b))); // glare radius
31-
pointSize = 2.0 * ceil(max_theta / degree_per_px);
32-
33-
float h = 0.0082234880783653 * pow(max_theta, 0.7369983254906639); // h, k, b - common constants, depending originally on star brightness
34-
float k = 38581.577272697796 * pow(max_theta, 2.368787717957141);
35-
v_max_tetha_hk = vec3(max_theta, h, k);
30+
float max_br = sqrt(max(color0.r, max(color0.g, color0.b)));
31+
float max_theta = 0.33435822702992773 * sqrt(max_br); // glare radius
32+
float k = 3.3e-5 * pow(max_theta, -2.5); // common constant, depending originally on star brightness
33+
float min_theta = max_theta / (pow(k, -0.5) + 1.0);
34+
pointSize = floor(max_theta / (sqrt(0.5 * br_limit / (k * max_br)) + 1.0) / degree_per_px);
35+
v_tetha_k = vec3(max_theta, min_theta, k);
3636
}
3737

3838
gl_PointSize = pointSize;

0 commit comments

Comments
 (0)