Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
vo6i authored Nov 7, 2024
1 parent 9aec21c commit f62603e
Showing 1 changed file with 69 additions and 29 deletions.
98 changes: 69 additions & 29 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,82 @@

<body>
<!--script type="text/javascript" src="https://rawgit.com/patriciogonzalezvivo/glslCanvas/master/dist/GlslCanvas.js"></script-->
<canvas id="glslCanvas" data-fragment='
<canvas id="glslCanvas" data-fragment='
// Author: Patricio Gonzalez Vivo respect from dclxviclan
#ifdef GL_ES
precision highp float;
#else
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform float u_time;
uniform sampler2D u_tex0;
uniform vec2 u_tex0Resolution;
uniform sampler2D u_logo; // data/logo.jpg
uniform vec2 u_logoResolution;
#include "lygia/math/const.glsl"
#include "lygia/space/ratio.glsl"
#include "lygia/space/scale.glsl"
#include "lygia/sdf/circleSDF.glsl"
uniform int pointerCount;
uniform vec3 pointers[10];
uniform vec2 resolution;
uniform sampler2D backbuffer;
uniform sampler2D noise;
uniform float time;
void main(void) {
float mx = max(resolution.x, resolution.y);
vec2 uv = gl_FragCoord.xy / mx;
vec3 o = 0.9 * texture2D(backbuffer,gl_FragCoord.xy/resolution).rgb;
float b = 0.0;
for (int n = 0; n < pointerCount; ++n) {
float d = 0.2/distance(uv, pointers[n].xy / mx);
d *= d;
b += d;
}
float t = time/3.0;
vec2 m = vec2(sin(t),cos(t));
m += vec2(sin(uv.y * 0.1 + sin(time) * 0.5)*1.7,0.0);
m*=0.8;
b *= texture2D(noise,m+gl_FragCoord.xy/resolution).r;
o = max(o,b * vec3(uv,float(pointerCount)/10.0));
gl_FragColor = vec4(o, 1.0);
vec2 sphereCoords(vec2 _st, float _scale){
float maxFactor = sin(1.570796327);
vec2 uv = vec2(0.0);
vec2 xy = 2.0 * _st.xy - 1.0;
float d = length(xy);
if (d < (2.0-maxFactor)){
d = length(xy * maxFactor);
float z = sqrt(1.0 - d * d);
float r = atan(d, z) / 3.1415926535 * _scale;
float phi = atan(xy.y, xy.x);
uv.x = r * cos(phi) + 0.5;
uv.y = r * sin(phi) + 0.5;
} else {
uv = _st.xy;
}
return uv;
}
vec4 sphereTexture(in sampler2D _tex, in vec2 _uv, float _time) {
vec2 st = sphereCoords(_uv, 1.0);
float aspect = u_tex0Resolution.y/u_tex0Resolution.x;
st.x = fract(st.x * aspect + _time);
return texture2D(_tex, st);
}
vec3 sphereNormals(in vec2 uv) {
uv = fract(uv)*2.0-1.0;
vec3 ret;
ret.xy = sqrt(uv * uv) * sign(uv);
ret.z = sqrt(abs(1.0 - dot(ret.xy,ret.xy)));
ret = ret * 0.5 + 0.5;
return mix(vec3(0.0), ret, smoothstep(1.0,0.98,dot(uv,uv)) );
}
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st = scale(st, 2.0);
st = ratio(st, u_resolution);
vec3 color = vec3(0.0);
color = sphereTexture(u_tex0, st, u_time * 0.01).rgb;
// Calculate sun direction
float speedSun = 0.25;
vec3 sunPos = normalize(vec3(cos(u_time * speedSun - HALF_PI), 0.0, sin(speedSun * u_time - HALF_PI)));
vec3 surface = normalize(sphereNormals(st)*2.0-1.0);
// Add Shadows
color *= clamp(dot(sunPos, surface), 0.0, 1.0);
// Blend black the edge of the sphere
float radius = 1.0 - circleSDF(st);
color *= smoothstep(0.001, 0.02, radius);
st = scale(st, 2.);
color += texture2D(u_logo, st).rgb * step(.0001,st.y) * step(st.y,.999);
gl_FragColor = vec4(color, 1.0);
}
' width="800" height="600" data-textures="data/moon.jpg"></canvas>
<script>
Expand Down

0 comments on commit f62603e

Please sign in to comment.