Skip to content

Commit 72eabc7

Browse files
committed
overhauling shader build pipeline
1 parent 8c7fab6 commit 72eabc7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2520
-789
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ else
66
endif
77
OUT=postcompiled/Rasters.js postcompiled/Shaders.js postcompiled/Academics.js
88
SCRIPTS = $(shell find precompiled/ -type f -name '*.js')
9-
SHADERS = $(shell find precompiled/ -type f -name '*.glsl.c')
9+
SHADERS = $(shell find precompiled/ -type f -name '*.glsl')
1010

1111
all: $(OUT)
1212

@@ -16,8 +16,8 @@ postcompiled/Rasters.js : precompiled/rasters/Rasters.js $(SCRIPTS) Makefile
1616
postcompiled/Shaders.js : precompiled/Shaders.js $(SHADERS) Makefile
1717
$(CPP) -E -P -I. -xc -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers -C precompiled/Shaders.js > $@
1818

19-
postcompiled/Academics.js : precompiled/Academics.js $(SHADERS) Makefile
20-
$(CPP) -E -P -I. -xc -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers -C precompiled/Academics.js > $@
19+
postcompiled/Academics.js : precompiled/Academics.js $(SHADERS) Makefile tools/glsl_tools
20+
$(CPP) -E -P -I. -xc -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers -C precompiled/Academics.js | python3 tools/glsl_tools/glsl_js.py > $@
2121

2222
clean:
2323
rm -f $(OUT)

_posts/2019-3-24-fast-atmospheric-scattering.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ If this were a college calculus course, you might think to use integration by su
9191

9292
<p>For my implementation, I define the "top" of the atmosphere to be 6 scale heights from the surface. Under these circumstances, I set `b = 0.45` and `a = 0.45`. I find this gives pretty good approximations for column density ratio given virtually any realistic value of `z` or `H`. See for yourself: follow the link <a href="https://www.desmos.com/calculator/mu12vadnte">here</a> and adjust the sliders for `H` and `z` and see how close the appoximation (red) gets to the actual column density (black)</p>
9393

94-
Lastly, if you're interested in borrowing some of my code, check out [raymarching.glsl.c](https://github.com/davidson16807/tectonics.js/blob/master/precompiled/academics/raymarching.glsl.c) in the Tectonics.js source code, or just copy/paste the code below:
94+
Lastly, if you're interested in borrowing some of my code, check out [raymarching.glsl](https://github.com/davidson16807/tectonics.js/blob/master/precompiled/academics/raymarching.glsl) in the Tectonics.js source code, or just copy/paste the code below:
9595

9696
<pre><code class="language-glsl">
9797
float approx_air_column_density_ratio_along_2d_ray_for_curved_world(

postcompiled/Academics.js

+47-49
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ const SOLAR_RADIUS = 695.7e6;
7070
const SOLAR_LUMINOSITY = 3.828e26;
7171
// watts
7272
const SOLAR_TEMPERATURE = 5772.;
73-
// kelvin
74-
75-
const PI = 3.14159265358979323846264338327950288419716939937510;
76-
const PHI = 1.6180339887;
77-
const BIG = 1e20;
78-
const SMALL = 1e-20;
7973
function maybe_int(
8074
/*bool*/ exists
8175
){
@@ -121,6 +115,43 @@ function maybe_vec4(
121115
};
122116
}
123117

118+
const PI = 3.14159265358979323846264338327950288419716939937510;
119+
const PHI = 1.6180339887;
120+
const BIG = 1e20;
121+
const SMALL = 1e-20;
122+
/*
123+
"bump" is the Alan Zucconi bump function.
124+
It's a fast and easy way to approximate any kind of wavelet or gaussian function
125+
Adapted from GPU Gems and Alan Zucconi
126+
from https://www.alanzucconi.com/2017/07/15/improving-the-rainbow/
127+
*/
128+
/*float*/
129+
function bump(
130+
/*float*/ x,
131+
/*float*/ edge0,
132+
/*float*/ edge1,
133+
/*float*/ height
134+
){
135+
let center = (edge1 + edge0) / 2.;
136+
let width = (edge1 - edge0) / 2.;
137+
let offset = (x - center) / width;
138+
return height * glm.max( 1. - offset * offset, 0.);
139+
}
140+
141+
/*
142+
"oplus" is the o-plus operator,
143+
or the reciprocal of the sum of reciprocals.
144+
It's a handy function that comes up a lot in some physics problems.
145+
It's pretty useful for preventing division by zero.
146+
*/
147+
/*float*/
148+
function oplus(
149+
/*float*/ a,
150+
/*float*/ b
151+
){
152+
return 1. / (1. / a + 1. / b);
153+
}
154+
124155
/*maybe_float*/
125156
function get_distance_along_line_to_union(
126157
/*maybe_float*/ shape1,
@@ -162,8 +193,8 @@ function get_distances_along_line_to_intersection(
162193
/*maybe_vec2*/ shape1,
163194
/*maybe_vec2*/ shape2
164195
){
165-
let x = shape1.exists && shape2.exists? glm.max( shape1.value.x, shape2.value.x) : 0.f;
166-
let y = shape1.exists && shape2.exists? glm.min( shape1.value.y, shape2.value.y) : 0.f;
196+
let x = shape1.exists && shape2.exists? glm.max( shape1.value.x, shape2.value.x) : 0.0;
197+
let y = shape1.exists && shape2.exists? glm.min( shape1.value.y, shape2.value.y) : 0.0;
167198
return maybe_vec2( glm.vec2( x, y), shape1.exists && shape2.exists && x < y);
168199
}
169200

@@ -193,7 +224,7 @@ function get_distance_along_2d_line_to_line(
193224
// offset
194225
let R = D['-']( A['*']( glm.dot( D, A)));
195226
// rejection
196-
return maybe_float( glm.length( R) / glm.dot( B, glm.normalize( (R)["*"]( -1))), glm.abs( glm.abs( glm.dot( A, B)) - 1.f) > 0.f);
227+
return maybe_float( glm.length( R) / glm.dot( B, glm.normalize( (R)["*"]( -1))), glm.abs( glm.abs( glm.dot( A, B)) - 1.0) > 0.0);
197228
}
198229

199230
/*
@@ -218,7 +249,7 @@ function get_distance_along_2d_line_to_ray(
218249
// distance along B
219250
let xA = xB / glm.dot( B, A);
220251
// distance along A
221-
return maybe_float( xB, glm.abs( glm.abs( glm.dot( A, B)) - 1.f) > 0.f && xA > 0.f);
252+
return maybe_float( xB, glm.abs( glm.abs( glm.dot( A, B)) - 1.0) > 0.0 && xA > 0.0);
222253
}
223254

224255
/*
@@ -244,7 +275,7 @@ function get_distance_along_2d_line_to_line_segment(
244275
// distance along B
245276
let xA = xB / glm.dot( B, A);
246277
// distance along A
247-
return maybe_float( xB, glm.abs( glm.abs( glm.dot( A, B)) - 1.f) > 0.f && 0. < xA && xA < glm.length( B2['-']( B1)));
278+
return maybe_float( xB, glm.abs( glm.abs( glm.dot( A, B)) - 1.0) > 0.0 && 0. < xA && xA < glm.length( B2['-']( B1)));
248279
}
249280

250281
/*maybe_vec2*/
@@ -310,7 +341,7 @@ function get_distance_along_3d_line_nearest_to_line(
310341
// cross
311342
let R = D['-']( (A['*']( glm.dot( D, A)))['-']( C['*']( glm.dot( D, C))));
312343
// rejection
313-
return maybe_float( glm.length( R) / -glm.dot( B, glm.normalize( R)), glm.abs( glm.abs( glm.dot( A, B)) - 1.f) > 0.f);
344+
return maybe_float( glm.length( R) / -glm.dot( B, glm.normalize( R)), glm.abs( glm.abs( glm.dot( A, B)) - 1.0) > 0.0);
314345
}
315346

316347
/*
@@ -334,7 +365,7 @@ function get_distance_along_3d_line_nearest_to_ray(
334365
// distance along B
335366
let xA = xB / glm.dot( B, A);
336367
// distance along A
337-
return maybe_float( xB, glm.abs( glm.abs( glm.dot( A, B)) - 1.f) > 0.f && xA > 0.f);
368+
return maybe_float( xB, glm.abs( glm.abs( glm.dot( A, B)) - 1.0) > 0.0 && xA > 0.0);
338369
}
339370

340371
/*
@@ -359,7 +390,7 @@ function get_distance_along_3d_line_nearest_to_line_segment(
359390
// distance along B
360391
let xA = xB / glm.dot( B, A);
361392
// distance along A
362-
return maybe_float( xB, glm.abs( glm.abs( glm.dot( A, B)) - 1.f) > 0.f && 0. < xA && xA < glm.length( B1['-']( B0)));
393+
return maybe_float( xB, glm.abs( glm.abs( glm.dot( A, B)) - 1.0) > 0.0 && 0. < xA && xA < glm.length( B1['-']( B0)));
363394
}
364395

365396
/*
@@ -521,7 +552,7 @@ function get_distances_along_3d_line_to_infinite_cylinder(
521552
let a = 1.0 - BA * BA;
522553
let b = glm.dot( D, A) - BD * BA;
523554
let c = glm.dot( D, D) - BD * BD - r * r;
524-
let h = glm.sqrt( glm.max( b * b - a * c, 0.f));
555+
let h = glm.sqrt( glm.max( b * b - a * c, 0.0));
525556
return maybe_vec2( glm.vec2( (-b + h) / a, (-b - h) / a), h > 0.0);
526557
}
527558

@@ -621,7 +652,7 @@ function get_distance_along_3d_line_to_infinite_cone(
621652
let c = glm.dot( D, B) * glm.dot( D, B) - glm.dot( D, D) * cosb * cosb;
622653
let det = b * b - 4. * a * c;
623654
if (det < 0.){
624-
return maybe_float( 0.f, false);
655+
return maybe_float( 0.0, false);
625656
}
626657

627658
det = glm.sqrt( det);
@@ -1165,39 +1196,6 @@ function get_rgb_fraction_of_light_transmitted_through_fluid_along_flat_surface(
11651196
return Math.exp( ((beta_ray['+']( beta_mie['+']( beta_abs))))['*']( -sigma));
11661197
}
11671198

1168-
/*
1169-
"bump" is the Alan Zucconi bump function.
1170-
It's a fast and easy way to approximate any kind of wavelet or gaussian function
1171-
Adapted from GPU Gems and Alan Zucconi
1172-
from https://www.alanzucconi.com/2017/07/15/improving-the-rainbow/
1173-
*/
1174-
/*float*/
1175-
function bump(
1176-
/*float*/ x,
1177-
/*float*/ edge0,
1178-
/*float*/ edge1,
1179-
/*float*/ height
1180-
){
1181-
let center = (edge1 + edge0) / 2.;
1182-
let width = (edge1 - edge0) / 2.;
1183-
let offset = (x - center) / width;
1184-
return height * glm.max( 1. - offset * offset, 0.);
1185-
}
1186-
1187-
/*
1188-
"oplus" is the o-plus operator,
1189-
or the reciprocal of the sum of reciprocals.
1190-
It's a handy function that comes up a lot in some physics problems.
1191-
It's pretty useful for preventing division by zero.
1192-
*/
1193-
/*float*/
1194-
function oplus(
1195-
/*float*/ a,
1196-
/*float*/ b
1197-
){
1198-
return 1. / (1. / a + 1. / b);
1199-
}
1200-
12011199
/*
12021200
This function returns a rgb vector that best represents color at a given wavelength
12031201
It is from Alan Zucconi: https://www.alanzucconi.com/2017/07/15/improving-the-rainbow/

0 commit comments

Comments
 (0)