JSFiddle - React, Tailwind, and code Playground
by RGMGx
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - shaders - ocean</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div id="container"></div>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - webgl ocean
</div>
<script type="module">
import * as THREE from 'https://unpkg.com/three/build/three.module.js';
import Stats from 'https://unpkg.com/three/examples/jsm/libs/stats.module.js';
import { GUI } from 'https://unpkg.com/three/examples/jsm/libs/dat.gui.module.js';
import { OrbitControls } from 'https://unpkg.com/three/examples/jsm/controls/OrbitControls.js';
import { Water } from 'https://unpkg.com/three/examples/jsm/objects/Water.js';
import { Sky } from 'https://unpkg.com/three/examples/jsm/objects/Sky.js';
let container, stats;
let camera, scene, renderer;
let controls, water, sun, mesh;
init();
animate();
function init() {
container = document.getElementById( 'container' );
//
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
//
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 55, window.innerWidth / window.innerHeight, 1, 20000 );
camera.position.set( 30, 30, 100 );
//
sun = new THREE.Vector3();
// Water
const waterGeometry = new THREE.PlaneBufferGeometry( 10000, 10000 );
water = new Water(
waterGeometry,
{
textureWidth: 512,
textureHeight: 512,
waterNormals: new THREE.TextureLoader().load( 'https://cdn.rawgit.com/mrdoob/three.js/dev/examples/textures/waternormals.jpg', function ( texture ) {
texture.wrapS =...
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - particles - sprites</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - webgl particle sprites example<br/>
snowflakes by <a href="http://en.wikipedia.org/wiki/File:Sketch_of_snow_crystal_by_Ren%C3%A9_Descartes.jpg">René Descartes</a>
</div>
<script type="module">
import * as THREE from 'https://unpkg.com/three/build/three.module.js';
import Stats from 'https://unpkg.com/three/examples/jsm/libs/stats.module.js';
import { GUI } from 'https://unpkg.com/three/examples/jsm/libs/dat.gui.module.js';
let camera, scene, renderer, stats, parameters;
let mouseX = 0, mouseY = 0;
let windowHalfX = window.innerWidth / 2;
let windowHalfY = window.innerHeight / 2;
const materials = [];
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.z = 1000;
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2( 0x000000, 0.0008 );
const geometry = new THREE.BufferGeometry();
const vertices = [];
const textureLoader = new THREE.TextureLoader();
const sprite1 = textureLoader.load( 'textures/sprites/snowflake1.png' );
const sprite2 = textureLoader.load( 'textures/sprites/snowflake2.png' );
const sprite3 = textureLoader.load( 'textures/sprites/snowflake3.png' );
const sprite4 = textureLoader.load( 'textures/sprites/snowflake4.png' );
const sprite5 = textureLoader.load( 'textures/sprites/snowflake5.png' );
for ( let i = 0; i < 10000; i ++ ) {
const x = Math.random() * 2000 - 1000;
const y = Math.random() * 2000 - 1000;
const z = Math.random() *...