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 =...