Created
March 23, 2023 02:10
-
-
Save ybouhjira/e62cb56c365563ab2eaab68fc668a0f5 to your computer and use it in GitHub Desktop.
Stripped GLSL fragment shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as THREE from 'three' | |
const scene = new THREE.Scene(); | |
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); | |
const renderer = new THREE.WebGLRenderer(); | |
renderer.setSize(window.innerWidth, window.innerHeight); | |
document.body.appendChild(renderer.domElement); | |
const geometry = new THREE.BoxGeometry(1, 1, 1); | |
const material = new THREE.ShaderMaterial({ | |
vertexShader: ` | |
varying vec2 vUv; | |
void main() { | |
vUv = uv; | |
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); | |
} | |
`, | |
fragmentShader: ` | |
uniform float time; | |
varying vec2 vUv; | |
void main() { | |
gl_FragColor = vec4(vec3(step(0.5, mod(vUv.x * time, 1.0))), 1.0); | |
} | |
`, | |
uniforms: { | |
time: {value: 1.0}, | |
} | |
}); | |
const cube = new THREE.Mesh(geometry, material); | |
scene.add(cube); | |
camera.position.z = 5; | |
function animate() { | |
requestAnimationFrame(animate); | |
material.uniforms.time.value += 0.1; | |
renderer.render(scene, camera); | |
} | |
animate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment