Skip to content

Commit 7dce828

Browse files
-added more options
1 parent 1164072 commit 7dce828

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

src/main.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const controls = {
2828

2929
'Noise Color': [ 255, 255, 0 ],
3030
'Depth': 0.1,
31+
'Rows': 4,
32+
'TriScale': 1.0,
33+
'LowTriRange': -1.0,
34+
'HighTriRange': 1.0,
35+
'HeightT': 'Off',
36+
'SymbolScaleT': 'Off',
37+
'SymbolPositionT': 'Off'
38+
3139
};
3240

3341
let icosphere: Icosphere;
@@ -77,7 +85,14 @@ function main() {
7785
var f1 = gui.addFolder('Greeble Control');
7886

7987
f1.add(controls, 'Depth', 0, 0.5).step(0.02);
80-
88+
f1.add(controls, 'Rows', 2, 30).step(1);
89+
f1.add(controls, 'TriScale', 0.01, 1.5).step(0.01);
90+
f1.add(controls, 'LowTriRange', -1.0, 1.0).step(0.01);
91+
f1.add(controls, 'HighTriRange', -1.0, 1.0).step(0.01);
92+
f1.add(controls, 'HeightT', [ 'On', 'Off' ]);
93+
f1.add(controls, 'SymbolScaleT', [ 'On', 'Off' ]);
94+
f1.add(controls, 'SymbolPositionT', [ 'On', 'Off' ]);
95+
8196
var f2 = gui.addFolder('Animation');
8297

8398
f2.add(controls, 'Camera Animation', [ 'On', 'Off' ]);
@@ -152,6 +167,14 @@ function main() {
152167
icosphere.create();
153168
}
154169

170+
sdf.setRows(controls['Rows']);
171+
sdf.setTriScale(controls['TriScale']);
172+
sdf.setLowTriRange(controls['LowTriRange']);
173+
sdf.setHighTriRange(controls['HighTriRange']);
174+
sdf.setHightT(controls['HeightT'] == 'On' ? 1.0 : 0.0);
175+
sdf.setSymbolScaleT(controls['SymbolScaleT'] == 'On' ? 1.0 : 0.0);
176+
sdf.setSymbolPositionT(controls['SymbolPositionT'] == 'On' ? 1.0 : 0.0);
177+
155178
renderer.render(camera, time, height, color, noiseColor, sdf, [
156179
square,
157180
], false);

src/rendering/gl/ShaderProgram.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class ShaderProgram {
8181
unifUp: WebGLUniformLocation;
8282
unifDimensions: WebGLUniformLocation;
8383

84+
unifRows: WebGLUniformLocation;
85+
unifTriScale: WebGLUniformLocation;
86+
unifLowTriRange: WebGLUniformLocation;
87+
unifHighTriRange: WebGLUniformLocation;
88+
unifHightT: WebGLUniformLocation;
89+
unifSymbolScaleT: WebGLUniformLocation;
90+
unifSymbolPositionT: WebGLUniformLocation;
8491

8592
constructor(shaders: Array<Shader>) {
8693
this.prog = gl.createProgram();
@@ -111,6 +118,14 @@ class ShaderProgram {
111118
this.unifUp = gl.getUniformLocation(this.prog, "u_Up");
112119
this.unifDimensions = gl.getUniformLocation(this.prog, "u_Dimensions");
113120

121+
this.unifRows = gl.getUniformLocation(this.prog, "u_Rows");
122+
this.unifTriScale = gl.getUniformLocation(this.prog, "u_TriScale");
123+
this.unifLowTriRange = gl.getUniformLocation(this.prog, "u_LowTriRange");
124+
this.unifHighTriRange = gl.getUniformLocation(this.prog, "u_HighTriRange");
125+
this.unifHightT = gl.getUniformLocation(this.prog, "u_HeightT");
126+
this.unifSymbolScaleT = gl.getUniformLocation(this.prog, "u_SymbolScaleT");
127+
this.unifSymbolPositionT = gl.getUniformLocation(this.prog, "u_SymbolPositionT");
128+
114129

115130

116131

@@ -131,6 +146,14 @@ class ShaderProgram {
131146

132147
}
133148

149+
setRows(t: number){this.use();gl.uniform1f(this.unifRows, t)}
150+
setTriScale(t: number){this.use();gl.uniform1f(this.unifTriScale, t)}
151+
setLowTriRange(t: number){this.use();gl.uniform1f(this.unifLowTriRange, t)}
152+
setHighTriRange(t: number){this.use();gl.uniform1f(this.unifHighTriRange, t)}
153+
setHightT(t: number){this.use();gl.uniform1f(this.unifHightT, t)}
154+
setSymbolScaleT(t: number){this.use();gl.uniform1f(this.unifSymbolScaleT, t)}
155+
setSymbolPositionT(t: number){this.use();gl.uniform1f(this.unifSymbolPositionT, t)}
156+
134157
use() {
135158
if (activeProgram !== this.prog) {
136159
gl.useProgram(this.prog);

src/shaders/sdf-objects.glsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ float pyramidNormalSDF(vec3 p, float h, float depth, float depth_scale, float nu
260260
prisim_transform = transform(prisim_transform, vec3(0, PI/2.0, 0), vec3(_x, _y, _z)); // translate to the position on the face and rotate so prism "points outward"
261261
vec3 shape_transform = transform(prisim_transform, vec3(-slant+PI/2.0, 0.0, 0), vec3(0,0,0));
262262

263-
float noiseHeight = depth*(-1.0 + 2.0 * random3d(vec3(_x+j, _y+i, _z+g_rot)));
263+
// low = -1.0 high = 2.0
264+
float noiseHeight = depth*(u_LowTriRange + (u_HighTriRange - u_LowTriRange) * random3d(vec3(_x+j, _y+i, _z+g_rot)));
264265
float noiseTransform = depth_scale*noiseHeight;
265266
float zshift = noiseTransform;
266267
prisim_transform = transform(prisim_transform, vec3(-slant, 0, PI*mod(j,2.0)), vec3(0, 0, 0));
@@ -271,7 +272,7 @@ float pyramidNormalSDF(vec3 p, float h, float depth, float depth_scale, float nu
271272
float prisim = triprism(prisim_transform, greeble_width, greeble_height, abs(noiseTransform));
272273

273274
float scale = 0.02 + 0.04 * random(vec2(_x+i, _z+g_rot));
274-
shape_transform = transform(shape_transform, vec3(0, 0, 0), vec3(-0.01+0.02*random(vec2(_x+i+_y, _z+g_rot)), -0.01+0.02*random(vec2(_x+i, _z+g_rot)), abs(noiseTransform)), vec3(1.0 * scale, 1000.0 * scale, 1.0 * scale));
275+
shape_transform = transform(shape_transform, vec3(0, 0, 0), vec3(-0.01+0.02*random(vec2(_x+i+_y, _z+g_rot)), -0.01+0.02*random(vec2(_x+i, _z+g_rot)), 0.0), vec3(1.0 * scale, 1000.0 * scale, 1.0 * scale));
275276
prisim = flatSubtraction(prisim, randomSymbol(shape_transform, random(vec2(_x+j+i, _z+g_rot))));
276277

277278
if(noiseHeight > 0.0){

src/shaders/sdf1-frag.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ float sceneSDF(vec3 queryPos)
120120
final = pyramidNormalSDF(main_t, 0.5,
121121
u_NoiseHeight,
122122
0.5,
123-
5.0,
124-
1.0);
123+
u_Rows,
124+
u_TriScale);
125125

126126
//final = symbol3SDF(queryPos);
127127

src/shaders/toolbox.glsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
const float PI=3.14159265;
22
uniform float u_Time;
3+
uniform float u_Rows;
4+
uniform float u_TriScale;
5+
uniform float u_LowTriRange;
6+
uniform float u_HighTriRange;
7+
uniform float u_HeightT;
8+
uniform float u_SymbolScaleT;
9+
uniform float u_SymbolPositionT;
10+
11+
12+
313
float bias(float t, float b) {
414
return (t / ((((1.0/b) - 2.0)*(1.0 - t))+1.0));
515
}

0 commit comments

Comments
 (0)