My challenge involves dividing a shader into 6 columns and 3 rows, each with dimensions of 100vw by 100vh. The goal is to have the rows evenly proportioned by height. However, the width of the shader segments should vary in proportions of 17.65vw, 16.25vw, 16.32vw, 16.32vw, 16.25vw, and 17.15vw from left to right. Currently, all segments have the same width, preventing me from achieving the desired result.
I received the initial code from a web designer, which was built using React. Since I needed it in JavaScript, I rewrote the code but encountered an issue where the shader segments were only square-shaped and couldn't be adjusted for different shapes and sizes. Despite researching three.js and reviewing the provided code, I haven't been able to make it work as intended. Here is my code:
const canvas = document.getElementById('canvas');
const renderer = new THREE.WebGLRenderer({ canvas });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(
window.innerWidth / -2, window.innerWidth / 2,
window.innerHeight / 2, window.innerHeight / -2,
0.1, 1000
);
camera.position.z = 1;
window.addEventListener('resize', () => {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
camera.left = width / -2;
camera.right = width / 2;
camera.top = height / 2;
camera.bottom = height / -2;
camera.updateProjectionMatrix();
});
const vertexShader = `
varying vec2 vUv;
void main() {
vUv = uv;
vec4 modelPosition = modelMatrix * vec4(position, 1.0);
vec4 viewPosition = viewMatrix * modelPosition;
vec4 projectionPosition = projectionMatrix * viewPosition;
gl_Position = projectionPosition;
}
`;
const fragmentShader = `
uniform float time;
uniform vec2 resolution;
uniform vec2 pointer;
varying vec2 vUv;
// Fragment shader logic goes here
`;
const uniforms = {
time: { value: 0 },
resolution: { value: new THREE.Vector2(window.innerWidth, window.innerHeight) },
pointer: { value: new THREE.Vector2(0, 0) }
};
// Shader material setup
const geometry = new THREE.PlaneGeometry(window.innerWidth, window.innerHeight);
const plane = new THREE.Mesh(geometry, material);
scene.add(plane);
const clock = new THREE.Clock();
function animate() {
uniforms.time.value += clock.getDelta();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
#canvas {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
}
<canvas id="canvas"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
I am seeking assistance in making the shader's column (segments') width adjustable and distinct from each other. Can you please help me find a solution?