Import shader in three.js

2,636 Kb

How do I make an import shader in three.js?

Original from What is a import shader in three.js? How do you make a import shader in three.js? This script and codes were developed by Khangeldy on 09 November 2022, Wednesday.

Import shader in three.js Previews

Import shader in three.js - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>import shader in three.js</title> <link rel="stylesheet" href="css/style.css">
<body> <div id="container"></div>
<script id="vertex-shader" type="no-js"> #ifdef GL_ES precision highp float; #endif void main() { vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 ); gl_Position = projectionMatrix * mvPosition; }
<script id="fragment-shader" type="no-js">	precision mediump float;	uniform vec2 mouse;	uniform vec2 resolution;	uniform float time;	void main(void){	gl_FragColor = vec4(sin(sin(time)*length(gl_FragCoord.xy-resolution/2.0)+time*20.0));	}
</script> <script src=''></script> <script src="js/index.js"></script>

Import shader in three.js - Script Codes CSS Codes

body {	overflow: hidden;	margin: 0;	height: 100%;

Import shader in three.js - Script Codes JS Codes

window.addEventListener("load", function() { // Camera variables. var width = window.innerWidth; var height = window.innerHeight; var aspect = width / height; var fov = 65; var clipPlaneNear = 0.1; var clipPlaneFar = 1000; var clearColor = 0x221f26; var clearAlpha = 1.0; // main container. var $container = document.getElementById('container'); // Clock var clock = new THREE.Clock(); // Set up uniform. var tuniform = { time: { type: 'f', value: 0.1 }, mouse: { type: 'v2', value: new THREE.Vector2() }, resolution: { type: 'v2', value: new THREE.Vector2() } }; var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(fov, aspect, clipPlaneNear, clipPlaneFar); camera.position.z = 500; var renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(width, height); renderer.setClearColor(new THREE.Color(clearColor, clearAlpha)); renderer.domElement.addEventListener('mousemove', recordMousePosition); function recordMousePosition(e) { var canvas = renderer.domElement; var rect = canvas.getBoundingClientRect(); tuniform.mouse.value.x = (e.clientX - rect.left) / canvas.clientWidth * 2 - 1; tuniform.mouse.value.y = (e.clientY - / canvas.clientHeight * -2 + 1; } tuniform.resolution.value.x = renderer.domElement.width; tuniform.resolution.value.y = renderer.domElement.height; $container.appendChild(renderer.domElement); var mat = new THREE.ShaderMaterial({ uniforms: tuniform, vertexShader: document.querySelector('#vertex-shader').textContent, fragmentShader: document.querySelector('#fragment-shader').textContent // side:THREE.DoubleSide }); var tobject = new THREE.Mesh(new THREE.PlaneGeometry(700, 394, 39), mat); scene.add(tobject); console.log(tuniform); var loop = function loop() { requestAnimationFrame(loop); tuniform.time.value += clock.getDelta(); renderer.render(scene, camera); }; loop();
}, false);
Import shader in three.js - Script Codes
Import shader in three.js - Script Codes
Home Page Home
Developer Khangeldy
Username Khangeldy
Uploaded November 09, 2022
Rating 3
Size 2,636 Kb
Views 32,384
Do you need developer help for Import shader in three.js?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Khangeldy (Khangeldy) Script Codes
Create amazing video scripts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!