Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 069d0eb

Browse files
committed
adds grid
1 parent 93e6918 commit 069d0eb

File tree

4 files changed

+73
-14
lines changed

4 files changed

+73
-14
lines changed

data/cubeMapQuadFrag.glsl

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
//grid code originally appears: https://github.com/diroru/domemod
12
#define PI 3.1415926535897932384626433832795
2-
3-
precision highp float;
4-
precision highp int;
3+
#define AA 0.1
54

65
uniform samplerCube cubemap;
76
uniform float aperture;
7+
uniform float renderGrid;
88

99
varying vec2 vertTexCoord;
1010

@@ -29,9 +29,50 @@ vec3 domeXYToXYZ(vec2 xy, float aperture) {
2929
return latLonToXYZ(domeXYToLatLon(xy, aperture));
3030
}
3131

32+
float rad2Deg(float r) {
33+
return r * 180.0 / PI;
34+
}
35+
36+
vec3 getLatitudeGrid(vec2 longLat, float gratOffset, float gratWidth, vec3 gratColour) {
37+
float gr = mod(rad2Deg(longLat.y) + gratWidth * 0.5, gratOffset) - gratWidth * 0.5;
38+
//return mix(gratColour, vec3(0.0), smoothstep(gratWidth*0.5 - AA, gratWidth*0.5 + AA, abs(gr)));
39+
return mix(gratColour, vec3(0.0), step(gratWidth, abs(gr)));
40+
}
41+
42+
vec3 getLongtitudeGrid(vec2 longLat, float gratOffset, float gratWidth, vec3 gratColour) {
43+
float longDeg = rad2Deg(longLat.x);
44+
float latDeg = rad2Deg(longLat.y);
45+
float go = gratWidth / sin(longLat.y);
46+
float gr = mod(longDeg + go , gratOffset) - go;
47+
//return mix(gratColour, vec3(0.0), smoothstep(go*0.5 - AA, go*0.5 + AA, abs(gr)));
48+
return mix(gratColour, vec3(0.0), step(go, abs(gr)));
49+
}
50+
51+
vec3 getGrid(vec2 longLat, vec3 colour, float gratOffset0, float gratWidth0, float gratOffset1, float gratWidth1) {
52+
vec3 longGrid_0 = getLongtitudeGrid(longLat, gratOffset0, gratWidth0, colour);
53+
vec3 longGrid_1 = getLongtitudeGrid(longLat, gratOffset1, gratWidth1, colour);
54+
vec3 latGrid_0 = getLatitudeGrid(longLat, gratOffset0, gratWidth0, colour);
55+
vec3 latGrid_1 = getLatitudeGrid(longLat, gratOffset1, gratWidth1, colour);
56+
vec3 grid_rgb = longGrid_0 + longGrid_1 + latGrid_0 + latGrid_1;
57+
//grid_rgb = longGrid_0;
58+
//TODO eg. vec3(0.0) as const
59+
return clamp(grid_rgb, vec3(0.0), vec3(1.0));
60+
//return grid_rgb;
61+
}
62+
63+
64+
3265
void main() {
33-
vec3 ray = domeXYToXYZ(vertTexCoord, aperture*PI);
34-
//vec3 rgb = ray * 0.5 + vec3(0.5); //DEBUG
66+
//vec3 color = vec3(textureCube(cubemap, vec3(vertTexCoord,1.0)));
67+
vec2 latLon = domeXYToLatLon(vertTexCoord, aperture*PI);
68+
vec3 ray = latLonToXYZ(latLon);
69+
//vec3 color = ray * 0.5 + vec3(0.5);
3570
vec3 color = vec3(textureCube(cubemap, ray));
36-
gl_FragColor = vec4(color, 1.0);
71+
72+
vec3 gridColor = getGrid(latLon.yx, vec3(1.0, 1.0, 0.0), 45.0, 0.6, 15.0, 0.2);
73+
// float gridX = 1.0 - smoothstep(gridWeight*0.5-AA, gridWeight*0.5+AA, mod(latLon.x - gridWeight*0.5, gridSize.x));
74+
// float gridY = 1.0 - smoothstep(gridWeight*0.5-AA, gridWeight*0.5+AA, mod(latLon.y - gridWeight*0.5, gridSize.y));
75+
76+
gl_FragColor = vec4(mix(color, gridColor, min(length(gridColor)*0.5, renderGrid)), 1.0);
77+
//gl_FragColor = vec4(rgb + gridColor, 1.0);
3778
}

examples/Basic/Basic.pde

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ import codeanticode.planetarium.*;
1818

1919
float cubeX, cubeY, cubeZ;
2020

21+
DomeCamera dc;
22+
int gridMode = Dome.NORMAL;
23+
2124
void setup() {
2225
// For the time being, only use square windows
23-
size(600, 600, Dome.RENDERER);
26+
size(1024, 1024, Dome.RENDERER);
27+
28+
dc = new DomeCamera(this);
2429
}
2530

2631
// Called one time per frame.
@@ -36,7 +41,7 @@ void draw() {
3641
background(0);
3742

3843
pushMatrix();
39-
translate(width/2, height/2, 300);
44+
translate(width/2, height/2, -300);
4045

4146
lights();
4247

@@ -56,9 +61,18 @@ void draw() {
5661
popMatrix();
5762
}
5863

64+
void mouseDragged() {
65+
//exaggerating dome aperture. 1f <=> 180°
66+
dc.setDomeAperture(map(mouseY,0,height,0.1f,4f));
67+
}
68+
5969
void keyPressed() {
6070
if (key == CODED) {
6171
if (keyCode == UP) cubeZ -= 5;
6272
else if (keyCode == DOWN) cubeZ += 5;
63-
}
73+
}
74+
if (key == ' ') {
75+
gridMode = gridMode == Dome.GRID ? Dome.NORMAL : Dome.GRID;
76+
dc.setMode(gridMode);
77+
}
6478
}

src/codeanticode/planetarium/Dome.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class Dome extends PGraphics3D {
7070
protected float domeDX, domeDY, domeDZ;
7171
protected float domeScale = 1;
7272
protected float domeAperture = 1f;
73+
protected float renderGrid = 0f;
7374

7475
protected Method borderMethod;
7576
protected Method screenMethod;
@@ -292,11 +293,16 @@ protected void domeRendering(boolean value) {
292293
}
293294
}
294295

295-
/*
296296
protected void renderGrid(boolean value) {
297-
renderGrid = value;
297+
renderGrid = value ? 1f : 0f;
298+
if(cubeMapQuadShader != null) {
299+
try {
300+
cubeMapQuadShader.set("renderGrid", renderGrid);
301+
} catch(Exception e) {
302+
e.printStackTrace();
303+
}
304+
}
298305
}
299-
*/
300306

301307
protected int getCurrentFace() {
302308
return currentFace;

src/codeanticode/planetarium/DomeCamera.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ public DomeCamera(PApplet parent) {
4343
}
4444

4545
public void setMode(int mode) {
46-
/*
4746
if (mode == Dome.NORMAL) {
4847
renderer.renderGrid(false);
4948
} else if (mode == Dome.GRID) {
5049
renderer.renderGrid(true);
5150
}
52-
*/
5351
}
5452

5553
public void setDomeAperture(float theAperture) {

0 commit comments

Comments
 (0)