mirror of
https://github.com/SamEyeBam/animate.git
synced 2025-09-28 15:05:25 +00:00
larry babby and threejs for glsl
This commit is contained in:
19
webGl/my-threejs-test/shaders/fragment.glsl
Normal file
19
webGl/my-threejs-test/shaders/fragment.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
varying vec3 vColor;
|
||||
|
||||
void main() {
|
||||
float distance = length(gl_PointCoord - vec2(0.5, 0.5));
|
||||
float radius = 0.5; // The radius of the circle, where 0.5 is the edge of the point sprite
|
||||
float intensity = 0.5; // Gaussian for smooth intensity increase
|
||||
// float intensity = exp(-pow(distance * 3.0, 2.0)); // Gaussian for smooth intensity increase
|
||||
|
||||
// If the distance is greater than the radius, discard the fragment (make it transparent)
|
||||
if (distance > radius) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Use the intensity to modulate the color within the circle
|
||||
vec3 brightColor = vColor * intensity;
|
||||
brightColor = clamp(brightColor, 0.0, 2.5);
|
||||
|
||||
gl_FragColor = vec4(brightColor, 1.0); // Full alpha within the circle
|
||||
}
|
33
webGl/my-threejs-test/shaders/vertex.glsl
Normal file
33
webGl/my-threejs-test/shaders/vertex.glsl
Normal file
@@ -0,0 +1,33 @@
|
||||
uniform float time;
|
||||
uniform vec3 color1;
|
||||
uniform vec3 color2;
|
||||
varying vec3 vColor;
|
||||
|
||||
const float PI = 3.1415926535897932384626433832795;
|
||||
const float goldenAngle = PI * (3.0 - sqrt(5.0));
|
||||
|
||||
void main() {
|
||||
// Calculate the normalized distance from center
|
||||
float index = float(gl_VertexID);
|
||||
float radiuss = sqrt(index) * 5.0;
|
||||
float normalizedRadius = radiuss / 200.0; // Adjust this divisor based on your pattern's size
|
||||
|
||||
// Calculate the angle for each point based on its index
|
||||
float angle = index * (goldenAngle + time * 0.001);
|
||||
if (mod(index,2.0) != 0.0){
|
||||
angle *=-1.0;
|
||||
}
|
||||
|
||||
// Color changes over time - Adding a slow wave effect based on the distance from center
|
||||
float colorTime = time * -2.1; // Slow down the color change over time
|
||||
float colorWave = sin(normalizedRadius * PI * 2.0 + colorTime); // Wave based on distance and time
|
||||
float colorMixFactor = colorWave * 0.5 + 0.5; // Normalize the wave between 0 and 1
|
||||
|
||||
vColor = mix(color1, color2, colorMixFactor); // Mix the colors based on the computed factor
|
||||
|
||||
// Calculate the animated position
|
||||
vec3 animatedPosition = vec3(radiuss * cos(angle), radiuss * sin(angle), 0.0);
|
||||
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4(animatedPosition, 1.0);
|
||||
gl_PointSize = 10.0;
|
||||
}
|
Reference in New Issue
Block a user