three.js dev tsl-bumpMap test with procedural textures

by GnanaSai

HTML

<script type="importmap">
	{
		"imports": {
			"three": "https://raw.githack.com/mrdoob/three.js/dev/build/three.webgpu.js",
      "three/webgpu": "https://raw.githack.com/mrdoob/three.js/dev/build/three.webgpu.js",
      "three/tsl": "https://raw.githack.com/mrdoob/three.js/dev/build/three.tsl.js",
      "three/addons/": "https://raw.githack.com/mrdoob/three.js/dev/examples/jsm/"
		}
	}
</script>

CSS

body {
	margin: 0px;
}

JavaScript

import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { bumpMap, color, float, mx_noise_float, range, texture, uniform, uniformTexture, uv, vec3 } from "three/tsl";

let mesh, renderer, scene, camera, controls;

init();

function init() {

    // renderer
    renderer = new THREE.WebGPURenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setAnimationLoop(animate);
    document.body.appendChild(renderer.domElement);

    // scene
    scene = new THREE.Scene();
    scene.background = new THREE.Color(0x000000);

    // camera
    camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.set(20, 20, 20);

    // controls
    controls = new OrbitControls(camera, renderer.domElement);

    // ambient
    scene.add(new THREE.AmbientLight(0x222222));

    // light
    const light = new THREE.DirectionalLight(0xffffff, 1);
    light.position.set(20, 20, 0);
    scene.add(light);

    // axes
    scene.add(new THREE.AxesHelper(20));

    // geometry
    const geometry = new THREE.SphereGeometry(5, 32, 16);

    // material
    const material = new THREE.MeshPhysicalNodeMaterial({
        color: 0x00ffff,
        flatShading: false,
    });

    material.normalNode = bumpMap(mx_noise_float(uv().mul(10), 1, 0.5));

    // material.colorNode = mx_noise_float(uv().mul(10), 1, 0);

    // mesh
    mesh = new THREE.Mesh(geometry, material);
    scene.add(mesh);

}

function animate() {

    renderer.render(scene, camera);

}