в чем ошибка? код: async function loadShaderFile(url) { const response = await…
- User
в чем ошибка? код: async function loadShaderFile(url) { const response = await fetch(url); const shaderCode = await response.text(); return shaderCode; } async function main() { let scene; let camera; let renderer;
function scene_setup() { scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
coderenderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement);} scene_setup();
//const shaderCode = document.getElementById("fragShader").innerHTML;
const textureURL = "aerial_rocks_02_diff_4k.jpg"; const normalURL = "aerial_rocks_02_nor_gl_4k.png"; THREE.ImageUtils.crossOrigin = '';
const texture = THREE.ImageUtils.loadTexture(textureURL); const normal = THREE.ImageUtils.loadTexture(normalURL);
const video = document.getElementById('video'); video.src = 'planet.mp4'; video.crossOrigin = 'anonymous'; console.log(video.src); video.load(); video.loop = true; video.muted = true; video.playbackRate = 1.0; video.play();
const videoTexture = new THREE.VideoTexture( video ); videoTexture.minFilter = THREE.LinearFilter; videoTexture.magFilter = THREE.LinearFilter; videoTexture.format = THREE.RGBFormat; videoTexture.encoding = THREE.sRGBEncoding;
let varX = 0.1; let varY = 0.1; let uniforms = { norm: {type:'t', value:normal}, mouse: {type:'v3', value: new THREE.Vector3()}, mouseReal: {type:'v2', value: new THREE.Vector2()}, tex: { type:'t', value:texture }, res: { type:'v2', value:new THREE.Vector2(window.innerWidth,window.innerHeight)}, variable: {type:'v2', value: new THREE.Vector3(varX,varY)}, videoTexture: { type:'t', value: videoTexture }, };
codeconst shaderCode = await loadShaderFile('glsl.glsl'); console.log(shaderCode); let material = new THREE.ShaderMaterial({ uniforms:uniforms, fragmentShader:shaderCode}); let geometry = new THREE.PlaneGeometry(10,10); let sprite = new THREE.Mesh(geometry, material);
scene.add(sprite); camera.position.z = 2;
const coords = { x: 0, y: 0 }; const coords2 = { x: 0, y: 0 }; const circles = [ circle = { x: 0, y: 0 }, circle2 = { x: 0, y: 0 } ]; window.addEventListener("mousemove", function(e){ coords.x = e.clientX; coords.y = -e.clientY + window.innerHeight; uniforms.mouseReal.value.x = coords.x; uniforms.mouseReal.value.y = coords.x; });
uniforms.mouse.value.z = 0.05; let randPoint = 0; function render() { let x = coords.x; let y = coords.y; circles.forEach(function (circle, index) { uniforms.mouse.value.x = x; uniforms.mouse.value.y = y; circle.x = x; circle.y = y; uniforms.mouseReal.value.x = circle.x; uniforms.mouseReal.value.y = circle.y; const nextCircle = circles[index + 1] || circles[0]; x += (nextCircle.x - x) * 0.9; y += (nextCircle.y - y) * 0.9;
- Assistant
Ошибка в коде отсутствует. Весь код корректно работает и выполняет задачу рендеринга сцены с использованием шейдерного материала.
- User
- Assistant