Skip to content

Commit 944e053

Browse files
committed
Add ozone example (WIP)
1 parent 8a9a638 commit 944e053

11 files changed

+2301
-0
lines changed

Examples/Ozone/Ozone-Calc.ipynb

+648
Large diffs are not rendered by default.

Examples/Ozone/Ozone.ipynb

+1,204
Large diffs are not rendered by default.

Examples/Ozone/blank.png

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Earth/blank.png

Examples/Ozone/screen.frag

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
in vec4 vColour;
2+
in vec3 vVertex;
3+
in vec2 vTexCoord;
4+
uniform sampler2D uTexture;
5+
out vec4 outColour;
6+
//Custom uniform
7+
uniform vec2 size = vec2(1.0, 1.0);
8+
uniform vec2 offset = vec2(0.0,0.0);
9+
10+
void main(void)
11+
{
12+
vec2 texCoord = (vTexCoord - offset) / size;
13+
texCoord.y = 1.0 - texCoord.y;
14+
15+
if (texCoord.x >= 0.0 && texCoord.y >= 0.0 && texCoord.x <= 1.0 && texCoord.y <= 1.0)
16+
outColour = texture(uTexture, texCoord);
17+
else
18+
discard;
19+
20+
//Discard transparent to skip depth write
21+
//This fixes depth buffer output interfering with other objects
22+
// in transparent areas
23+
if (outColour.a <= 0.1)
24+
discard;
25+
}
26+

Examples/Ozone/screen.vert

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
in vec3 aVertexPosition;
2+
in vec3 aVertexNormal;
3+
in vec4 aVertexColour;
4+
in vec2 aVertexTexCoord;
5+
6+
uniform mat4 uMVMatrix;
7+
uniform mat4 uPMatrix;
8+
uniform mat4 uNMatrix;
9+
10+
uniform vec4 uColour;
11+
12+
out vec4 vColour;
13+
out vec3 vVertex;
14+
out vec3 vNormal;
15+
out vec2 vTexCoord;
16+
void main(void) {
17+
gl_Position = vec4(aVertexPosition, 1.0);
18+
19+
vNormal = normalize(mat3(uNMatrix) * aVertexNormal);
20+
21+
if (uColour.a > 0.0)
22+
vColour = uColour;
23+
else
24+
vColour = aVertexColour;
25+
26+
vTexCoord = aVertexTexCoord;
27+
vVertex = aVertexPosition;
28+
}
29+

Examples/Ozone/triShader_oz.frag

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
in vec4 vColour;
2+
in vec3 vNormal;
3+
in vec3 vPosEye;
4+
in vec3 vVertex;
5+
in vec2 vTexCoord;
6+
in vec3 vLightPos;
7+
8+
uniform float uOpacity;
9+
uniform bool uLighting;
10+
uniform float uBrightness;
11+
uniform float uContrast;
12+
uniform float uSaturation;
13+
uniform float uAmbient;
14+
uniform float uDiffuse;
15+
uniform float uSpecular;
16+
uniform float uShininess;
17+
18+
uniform bool uTextured;
19+
uniform sampler2D uTexture;
20+
uniform vec3 uClipMin;
21+
uniform vec3 uClipMax;
22+
uniform bool uOpaque;
23+
uniform vec4 uLight;
24+
25+
//Custom
26+
uniform float height;
27+
28+
out vec4 outColour;
29+
30+
uniform bool uCalcNormal;
31+
32+
uniform mat4 uNMatrix;
33+
34+
void calcColour(vec3 colour, float alpha)
35+
{
36+
//Brightness adjust
37+
colour += uBrightness;
38+
//Saturation & Contrast adjust
39+
const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
40+
vec3 AvgLumin = vec3(0.5, 0.5, 0.5);
41+
vec3 intensity = vec3(dot(colour, LumCoeff));
42+
colour = mix(intensity, colour, uSaturation);
43+
colour = mix(AvgLumin, colour, uContrast);
44+
45+
//Gamma correction
46+
//https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model#OpenGL_Shading_Language_code_sample
47+
//const float screenGamma = 2.2; // Assume the monitor is calibrated to the sRGB color space
48+
//vec3 colorGammaCorrected = pow(color, vec3(1.0 / screenGamma));
49+
50+
outColour = vec4(colour, alpha);
51+
}
52+
53+
void main(void)
54+
{
55+
vec4 fColour = vColour;
56+
57+
//fColour = 1.0 - fColour;
58+
float alpha = 1.0; //fColour.a;
59+
60+
//With this blending mode, texture is blended over base colour,
61+
//and colour opacity has no effect on texture opacity
62+
//All desired texture opacity must be built in to the texture data
63+
//(Could add another blend mode if we want a dynamic texture opacity)
64+
vec4 tColour = texture(uTexture, vTexCoord);
65+
66+
//Blend the texure colour with the fragment colour using texture alpha
67+
fColour.rgb = tColour.rgb; //vec3(mix(fColour.rgb, tColour.rgb, tColour.a));
68+
69+
//fColour = 1.0 - fColour;
70+
//fColour = 0.5 * fColour + 0.25;
71+
//fColour = 1.0 - fColour;
72+
outColour = fColour; //vec4(, alpha);
73+
74+
//float lon = vTexCoord.x * 360.0;
75+
//if (int(lon) % 10 == 0)
76+
// outColour.r = 1.0;
77+
//float lat = vTexCoord.y * 360.0 - 180;
78+
79+
//Contour
80+
//if (length(abs(fColour.rgb - vec3(1.0, 1.0, 191.0/255.0))) < 0.06)
81+
//Threshold of 220dU in range [0,600] = 220/600 = 0.3666
82+
if (tColour.a < 0.3666)
83+
{
84+
fColour.rgb *= 0.95; //vec3(0.0, 0.0, 0.0);
85+
}
86+
//else
87+
// fColour.rgb = abs(fColour.rgb - vec3(1.0, 1.0, 191.0/255.0));
88+
89+
//outColour.a = 0.9; //alpha;
90+
alpha = 0.8;
91+
calcColour(fColour.rgb, alpha);
92+
}
93+

Examples/Ozone/triShader_oz.vert

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
in vec3 aVertexPosition;
2+
in vec3 aVertexNormal;
3+
in vec4 aVertexColour;
4+
in vec2 aVertexTexCoord;
5+
#ifndef WEBGL
6+
flat out vec4 vFlatColour;
7+
#endif
8+
9+
uniform mat4 uMVMatrix;
10+
uniform mat4 uPMatrix;
11+
uniform mat4 uNMatrix;
12+
13+
uniform vec4 uColour;
14+
uniform vec4 uLightPos;
15+
16+
out vec4 vColour;
17+
out vec3 vNormal;
18+
out vec3 vPosEye;
19+
out vec2 vTexCoord;
20+
out vec3 vVertex;
21+
out vec3 vLightPos;
22+
23+
void main(void)
24+
{
25+
vec4 mvPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
26+
vPosEye = vec3(mvPosition) / mvPosition.w;
27+
gl_Position = uPMatrix * mvPosition;
28+
29+
vNormal = normalize(mat3(uNMatrix) * aVertexNormal);
30+
31+
if (uColour.a > 0.0)
32+
vColour = uColour;
33+
else
34+
vColour = aVertexColour;
35+
36+
vTexCoord = aVertexTexCoord;
37+
#ifndef WEBGL
38+
vFlatColour = vColour;
39+
#endif
40+
vVertex = aVertexPosition;
41+
42+
//Head light, lightPos=(0,0,0) - vPosEye
43+
//vec3 lightDir = normalize(uLightPos.xyz - vPosEye);
44+
if (uLightPos.w < 0.5)
45+
{
46+
//Light follows camera - default mode
47+
vLightPos = uLightPos.xyz;
48+
}
49+
else
50+
{
51+
//Fixed Scene Light, when lightpos.w set to 1.0
52+
vLightPos = (uMVMatrix * vec4(uLightPos.xyz, 1.0)).xyz;
53+
}
54+
}
55+

Examples/Ozone/triShader_oz2.frag

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
in vec4 vColour;
2+
in vec3 vNormal;
3+
in vec3 vPosEye;
4+
in vec3 vVertex;
5+
in vec2 vTexCoord;
6+
in vec3 vLightPos;
7+
8+
uniform float uOpacity;
9+
uniform bool uLighting;
10+
uniform float uBrightness;
11+
uniform float uContrast;
12+
uniform float uSaturation;
13+
uniform float uAmbient;
14+
uniform float uDiffuse;
15+
uniform float uSpecular;
16+
uniform float uShininess;
17+
18+
uniform bool uTextured;
19+
uniform sampler2D uTexture;
20+
uniform vec3 uClipMin;
21+
uniform vec3 uClipMax;
22+
uniform bool uOpaque;
23+
uniform vec4 uLight;
24+
25+
//Custom
26+
uniform float height;
27+
28+
out vec4 outColour;
29+
30+
uniform bool uCalcNormal;
31+
32+
uniform mat4 uNMatrix;
33+
float sat = uSaturation;
34+
35+
void calcColour(vec3 colour, float alpha)
36+
{
37+
//Brightness adjust
38+
colour += uBrightness;
39+
//Saturation & Contrast adjust
40+
const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
41+
vec3 AvgLumin = vec3(0.5, 0.5, 0.5);
42+
vec3 intensity = vec3(dot(colour, LumCoeff));
43+
colour = mix(intensity, colour, sat);
44+
colour = mix(AvgLumin, colour, uContrast);
45+
46+
outColour = vec4(colour, alpha);
47+
}
48+
49+
void main(void)
50+
{
51+
vec4 fColour = vColour;
52+
53+
//fColour = 1.0 - fColour;
54+
float alpha = 1.0; //fColour.a;
55+
56+
vec4 tColour = texture(uTexture, vTexCoord);
57+
//Blend the texure colour with the fragment colour using texture alpha
58+
fColour.rgb = tColour.rgb; //vec3(mix(fColour.rgb, tColour.rgb, tColour.a));
59+
60+
//Light direction
61+
vec3 lightDir = normalize(vLightPos - vPosEye);
62+
//Calculate diffuse lighting
63+
vec3 N = normalize(vNormal);
64+
//Calculate diffuse component
65+
//Single side or two-sided lighting with abs()?
66+
float diffuse = dot(N, lightDir);
67+
if (uLight.w < 0.5)
68+
diffuse = abs(diffuse);
69+
else
70+
diffuse = max(diffuse, 0.0);
71+
72+
//Reduce the opacity as ozone conc decreases
73+
alpha = clamp(0.4+ pow(tColour.a,2.0), 0.0, 1.0); //0.2 + alpha * fColour.a; //0.7; //uOpacity;
74+
//alpha = clamp(pow(tColour.a,1.25), 0.0, 1.0); //0.2 + alpha * fColour.a; //0.7; //uOpacity;
75+
//Crank the saturation to better show colours as opacity reduced
76+
sat = 1.3 + 1.0 - alpha;
77+
calcColour(fColour.rgb, alpha);
78+
}
79+

0 commit comments

Comments
 (0)