Skip to content

Commit

Permalink
Closes #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
roice3 committed Apr 6, 2018
1 parent d095790 commit 06136ee
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
5 changes: 3 additions & 2 deletions js/HyperSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ var finishInit = function(fShader){
maxSteps:{type:"i", value:maxSteps},
sceneIndex:{type:"i", value: 1},
halfCubeWidthKlein:{type:"f", value: hCWK},
cut4:{type:"i", value:cut4},
sphereRad:{type:"f", value:sphereRad},
tubeRad:{type:"f", value:tubeRad},
horosphereSize:{type:"f", value:horosphereSize},
planeOffset:{type:"f", value:planeOffset}
horosphereSize:{type:"f", value:horosphereSize},
planeOffset:{type:"f", value:planeOffset}
},
vertexShader: document.getElementById('vertexShader').textContent,
fragmentShader: fShader,
Expand Down
13 changes: 13 additions & 0 deletions js/NonEuclideanMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ function PiOverNSafe(n)
return n == -1 ? 0 : Math.PI / n;
}

// Returns the geometry induced by a polygon with p sides, q meeting at each vertex.
function GetGeometry2D(p,q)
{
var test = 1.0 / p + 1.0 / q;
if( test > 0.5 )
return Geometry.Spherical;
else if( test == 0.5 )
return Geometry.Euclidean;

return Geometry.Hyperbolic;
}

// Returns the geometry induced by a {p,q{} polyhedron, r meeting at each edge.
function GetGeometry(p, q, r)
{
var t1 = Math.sin(PiOverNSafe(p)) * Math.sin(PiOverNSafe(r));
Expand Down
14 changes: 8 additions & 6 deletions js/SceneManipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var gens;
var invGens;
var hCWH = 0.6584789485;
var hCWK = 0.5773502692;
var cut4 = 2;
var sphereRad = 0.996216;
var tubeRad = 0.15;
var horosphereSize = -0.951621;
Expand Down Expand Up @@ -79,11 +80,11 @@ function updateUniformsFromUI()
// We want them to be slightly bigger than that so that they intersect.
// hOffset controls the thickness of edges at their smallest neck.
// (zero is a reasonable value, and good for testing.)
// Make hOffset a UI parameter??
var cut4 = GetGeometry2D( q, r );
var hOffset = guiInfo.edgeThickness / 10;

//Tube Radius
tubeRad = guiInfo.edgeThickness/10;
//Tube Radius
tubeRad = guiInfo.edgeThickness/10;

// sphereRad
sphereRad = midrad - hOffset;
Expand All @@ -104,17 +105,18 @@ function updateUniformsFromUI()
material.uniforms.generators.value = gens;
material.uniforms.invGenerators.value = invGens;
material.uniforms.halfCubeWidthKlein.value = hCWK;
material.uniforms.cut4.value = cut4;
material.uniforms.sphereRad.value = sphereRad;
material.uniforms.tubeRad.value = tubeRad;
material.uniforms.tubeRad.value = tubeRad;
material.uniforms.horosphereSize.value = horosphereSize;
material.uniforms.planeOffset.value = planeOffset;
material.uniforms.lightingModel.value = guiInfo.lightingModel;
material.uniforms.lightingModel.value = guiInfo.lightingModel;
}

//What we need to init our dat GUI
var initGui = function(){
var gui = new dat.GUI();
gui.add(material.uniforms.sceneIndex, 'value',{Sphere_horosphere: 1, Sphere_plane: 2, Edge_tubes: 3, Medial_surface: 4, Cube_planes: 5}).name("Scene");
gui.add(material.uniforms.sceneIndex, 'value',{Simplex_cuts: 1, Edge_tubes: 3, Medial_surface: 4, Cube_planes: 5}).name("Scene");
var lightingController = gui.add(guiInfo, 'lightingModel', {"Standard":0, "Foo": 1}).name("Lighting Model");
var edgeController = gui.add(guiInfo, 'edgeCase', {"5":1, "6":2, "7":3, "8":4, "9":5, "10":6, "11":7, "12":8}).name("Edge Degree");
var thicknessController = gui.add(guiInfo, 'edgeThickness', 0, 5).name("Edge Thickness");
Expand Down
5 changes: 5 additions & 0 deletions shaders/globalsInclude.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ uniform float tubeRad;
uniform float horosphereSize;
uniform float planeOffset;

// The type of cut (1=sphere, 2=horosphere, 3=plane) for the vertex opposite the fundamental simplex's 4th mirror.
// These integers match our values for the geometry of the honeycomb vertex figure.
// We'll need more of these later when we support more symmetry groups.
uniform int cut4;

//Quaternion Math
vec3 qtransform( vec4 q, vec3 v ){
return v + 2.0*cross(cross(v, -q.xyz ) + q.w*v, -q.xyz);
Expand Down
26 changes: 13 additions & 13 deletions shaders/hyperbolicScene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ float geodesicCylinderHSDFends(vec4 samplePoint, vec4 lightPoint1, vec4 lightPoi


float localSceneHSDF(vec4 samplePoint){
if(sceneIndex == 1){ // sphere and horosphere
if(sceneIndex == 1){ // cuts into the simplex
float sphere = sphereHSDF(samplePoint, ORIGIN, sphereRad);
float horosphere = horosphereHSDF(abs(samplePoint), idealCubeCornerKlein, horosphereSize);
float final = -unionSDF(horosphere, sphere);
float vertexSphere = 0.0;
if(cut4 == 2) {
vertexSphere = horosphereHSDF(abs(samplePoint), idealCubeCornerKlein, horosphereSize);
}
if(cut4 == 1 || cut4 == 3) { // Interesting that this works for finite spheres as well.
vec4 dualPoint = lorentzNormalize(vec4(halfCubeWidthKlein,halfCubeWidthKlein,halfCubeWidthKlein,1.0));
vertexSphere = geodesicPlaneHSDF(abs(samplePoint), dualPoint, planeOffset);
}
float final = -unionSDF(vertexSphere,sphere);
return final;
}
else if(sceneIndex == 2){ // sphere and plane
float sphere = sphereHSDF(samplePoint, ORIGIN, sphereRad);
vec4 dualPoint = lorentzNormalize(vec4(halfCubeWidthKlein,halfCubeWidthKlein,halfCubeWidthKlein,1.0));
float plane0 = geodesicPlaneHSDF(abs(samplePoint), dualPoint, planeOffset);
float final = -unionSDF(plane0, sphere);
return final;
}
else if(sceneIndex == 3){ // edge tubes
else if(sceneIndex == 2){ // edge tubes
samplePoint = abs(samplePoint);
// //now reflect until smallest xyz coord is z, and largest is x
if(samplePoint.x < samplePoint.z){
Expand All @@ -62,7 +62,7 @@ float localSceneHSDF(vec4 samplePoint){
float final = edgesDistance;
return final;
}
else if(sceneIndex == 4){ // edge medial surfaces
else if(sceneIndex == 3){ // edge medial surfaces
samplePoint = abs(samplePoint);
// //now reflect until smallest xyz coord is z, and largest is x
if(samplePoint.x < samplePoint.z){
Expand Down Expand Up @@ -91,7 +91,7 @@ float localSceneHSDF(vec4 samplePoint){
float final = 0.5*edgesDistance - 0.5*dualEdgesDistance;
return final;
}
else if(sceneIndex == 5){ // cube sides
else if(sceneIndex == 4){ // cube sides
/// draw sides of the cube fundamental domain
vec4 dualPoint0 = lorentzNormalize(vec4(1.0/halfCubeWidthKlein,0.0,0.0,1.0));
vec4 dualPoint1 = lorentzNormalize(vec4(0.0,1.0/halfCubeWidthKlein,0.0,1.0));
Expand Down

0 comments on commit 06136ee

Please sign in to comment.