-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from FarazzShaikh/dev
1.4.0
- Loading branch information
Showing
31 changed files
with
609 additions
and
65 deletions.
There are no files selected for viewing
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
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>gl-Noise • Curl</title> | ||
<link href="../main.css" rel="stylesheet" /> | ||
<style> | ||
body { | ||
background-color: #3a4042; | ||
} | ||
.Info { | ||
color: white; | ||
} | ||
</style> | ||
</head> | ||
<body type="0"> | ||
<div class="Info">Particles via Curl Noise.</div> | ||
<script type="module" src="./main.js" defer></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import * as THREE from "https://cdn.skypack.dev/three"; | ||
import { OrbitControls } from "https://cdn.skypack.dev/three/examples/jsm/controls/OrbitControls.js"; | ||
|
||
import { CustomShaderMaterial, TYPES } from "../lib/three-csm.module.js"; | ||
import { loadShadersCSM, Common, Simplex } from "../../build/glNoise.m.js"; | ||
|
||
import waves from "./waves.js"; | ||
|
||
function lights(scene) { | ||
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5, 100); | ||
const light = new THREE.HemisphereLight(0xffffff, 0xf7d9aa, 0.5); | ||
|
||
scene.add(light); | ||
scene.add(directionalLight); | ||
|
||
directionalLight.position.set(0, 1, 0); //default; light shining from top | ||
directionalLight.castShadow = true; | ||
|
||
directionalLight.shadow.mapSize.width = 512; // default | ||
directionalLight.shadow.mapSize.height = 512; // default | ||
directionalLight.shadow.camera.near = 0.5; // default | ||
directionalLight.shadow.camera.far = 500; | ||
} | ||
|
||
function map(x, in_min, in_max, out_min, out_max) { | ||
return ((x - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min; | ||
} | ||
|
||
function rand(min, max) { | ||
return map(Math.random(), 0, 1, min, max); | ||
} | ||
|
||
const v = { | ||
defines: "./shaders/particle_defines.glsl", | ||
header: "./shaders/particle_header.glsl", | ||
main: "./shaders/particle_main.glsl", | ||
}; | ||
|
||
const f = { | ||
defines: "./shaders/frag/defines.glsl", | ||
header: "./shaders/frag/header.glsl", | ||
main: "./shaders/frag/main.glsl", | ||
}; | ||
|
||
(async () => { | ||
const { defines: vdefines, header: vheader, main: vmain } = await loadShadersCSM(v); | ||
const { defines: fdefines, header: fheader, main: fmain } = await loadShadersCSM(f); | ||
const renderer = new THREE.WebGLRenderer({ alpha: true }); | ||
renderer.setSize(window.innerWidth, window.innerHeight); | ||
renderer.setPixelRatio(window.devicePixelRatio); | ||
renderer.shadowMap.enabled = true; | ||
renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap | ||
document.body.appendChild(renderer.domElement); | ||
|
||
const fov = 60; | ||
const aspect = window.innerWidth / window.innerHeight; | ||
const near = 0.1; | ||
const far = 200; | ||
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); | ||
|
||
const controls = new OrbitControls(camera, renderer.domElement); | ||
camera.position.set(7, 7, 7); | ||
|
||
const scene = new THREE.Scene(); | ||
|
||
lights(scene); | ||
|
||
const loader = new THREE.TextureLoader(); | ||
const disk = loader.load("./textures/circle-sprite.png"); | ||
|
||
const geometry = new THREE.IcosahedronGeometry(4, 64); | ||
console.log(geometry.attributes.position.count); | ||
const material = new CustomShaderMaterial({ | ||
baseMaterial: TYPES.POINTS, | ||
vShader: { | ||
defines: vdefines, | ||
header: vheader, | ||
main: vmain, | ||
}, | ||
fShader: { | ||
defines: fdefines, | ||
header: fheader, | ||
main: fmain, | ||
}, | ||
uniforms: { | ||
uShift: { | ||
value: 0, | ||
}, | ||
uShape: { | ||
value: disk, | ||
}, | ||
uScale: { | ||
value: window.innerHeight / 2, | ||
}, | ||
uTime: { | ||
value: 0, | ||
}, | ||
uTargetPos: { | ||
value: new THREE.Vector3(0), | ||
}, | ||
}, | ||
passthrough: { | ||
size: 0.05, | ||
}, | ||
}); | ||
|
||
const points = new THREE.Points(geometry, material); | ||
|
||
scene.add(points); | ||
|
||
const targetPos = new THREE.Vector3(); | ||
|
||
renderer.domElement.addEventListener("pointermove", (event) => { | ||
var vec = new THREE.Vector3(); // create once and reuse | ||
var pos = new THREE.Vector3(); // create once and reuse | ||
|
||
vec.set((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window.innerHeight) * 2 + 1, 0.5); | ||
|
||
vec.unproject(camera); | ||
|
||
vec.sub(camera.position).normalize(); | ||
|
||
var distance = -camera.position.z / vec.z; | ||
|
||
pos.copy(camera.position).add(vec.multiplyScalar(distance)); | ||
targetPos.x = pos.x; | ||
targetPos.y = pos.y; | ||
targetPos.z = pos.z; | ||
}); | ||
|
||
const render = (time) => { | ||
if (material && material.uniforms) { | ||
material.uniforms.uTime.value = time * 0.001; | ||
// const p = new THREE.Vector3(targetPos).sub(material.uniforms.uTargetPos.value).multiplyScalar(0.05); | ||
material.uniforms.uTargetPos.value = targetPos; | ||
} | ||
|
||
requestAnimationFrame(render); | ||
renderer.render(scene, camera); | ||
controls.update(); | ||
}; | ||
|
||
render(); | ||
})(); |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
uniform float uShift; | ||
uniform sampler2D uShape; | ||
|
||
varying vec2 vUv; | ||
varying vec3 vPosition; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
vec2 uv = vUv; | ||
uv.x += uShift; | ||
|
||
vec4 shapeData = texture2D(uShape, gl_PointCoord); | ||
if (shapeData.a < 0.0625) | ||
discard; | ||
|
||
vec4 newColor = vec4(vPosition, 1.0); | ||
newColor = newColor * shapeData; |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
uniform float uScale; | ||
uniform float uTime; | ||
uniform vec3 uTargetPos; | ||
|
||
varying vec2 vUv; | ||
varying vec3 vPosition; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
vec3 p = position; | ||
// p += uTargetPos * 0.1; | ||
|
||
vec3 f = gln_curl((p * 0.2) + uTime * 0.05); | ||
|
||
vUv = uv; | ||
|
||
vec3 newPos = position + f; | ||
|
||
vec3 seg = newPos - uTargetPos; | ||
vec3 dir = normalize(seg); | ||
float dist = length(seg); | ||
if (dist < 3.) { | ||
float force = clamp(1. / (dist * dist), 0., 1.); | ||
newPos += dir * force; | ||
} | ||
|
||
vPosition = newPos; | ||
vec3 newNormal = normal; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as THREE from "https://cdn.skypack.dev/three"; | ||
import { Common } from "../../build/glNoise.m.js"; | ||
import { CustomShaderMaterial, TYPES } from "../lib/three-csm.module.js"; | ||
|
||
export default function waves(scene, mobile) { | ||
let material; | ||
material = new CustomShaderMaterial({ | ||
baseMaterial: TYPES.TOON, | ||
vShader: { | ||
defines: ` `, | ||
header: ` | ||
varying vec3 vPosition; | ||
`, | ||
main: ` | ||
vec3 newPos = position; | ||
vPosition = position; | ||
vec3 newNormal = normal; | ||
`, | ||
}, | ||
fShader: { | ||
defines: ` `, | ||
header: ` | ||
${Common} | ||
varying vec3 vPosition; | ||
vec4 calcColor() { | ||
vec4 diffuseColor; | ||
float mask; | ||
mask = mix(0.0, 1.0, gln_map(vPosition.z, -5.0, 5.0, 0.0, 1.0)); | ||
mask = pow(mask, 8.0); | ||
diffuseColor = vec4(1.,0.929,0.851,1.); | ||
diffuseColor.rgb *= mask * 0.65; | ||
diffuseColor.a *= mask; | ||
return diffuseColor; | ||
} | ||
`, | ||
main: ` | ||
vec4 newColor = calcColor(); | ||
`, | ||
}, | ||
uniforms: {}, | ||
passthrough: {}, | ||
}); | ||
|
||
const geometry = new THREE.BoxGeometry(7, 7, 10, 1, 1, 1); | ||
const plane = new THREE.Mesh(geometry, material); | ||
plane.rotateX(-Math.PI / 2); | ||
plane.position.y = -7; | ||
plane.receiveShadow = true; | ||
|
||
if (!mobile) scene.add(plane); | ||
|
||
function displace(dt) {} | ||
|
||
return displace; | ||
} |
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
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
Oops, something went wrong.