Fix: TV screen material renders video as is

This commit is contained in:
Dejvino 2025-11-17 13:35:51 +01:00
parent 272c4267a3
commit 1a7b93bc7c
3 changed files with 47 additions and 6 deletions

View File

@ -0,0 +1,18 @@
export const screenVertexShader = `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
export const screenFragmentShader = `
varying vec2 vUv;
uniform sampler2D videoTexture;
void main() {
// Sample the video texture
gl_FragColor = texture2D(videoTexture, vUv);
}
`;

View File

@ -1,6 +1,7 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { state } from '../state.js'; import { state } from '../state.js';
import { createVcr } from './vcr.js'; import { createVcr } from './vcr.js';
import { screenVertexShader, screenFragmentShader } from '../shaders/screen-shaders.js';
export function createTvSet(x, z, rotY) { export function createTvSet(x, z, rotY) {
// --- Materials (MeshPhongMaterial) --- // --- Materials (MeshPhongMaterial) ---
@ -177,12 +178,15 @@ export function turnTvScreenOn() {
if (state.tvScreen.material) { if (state.tvScreen.material) {
state.tvScreen.material.dispose(); state.tvScreen.material.dispose();
} }
state.tvScreen.material = new THREE.MeshBasicMaterial({
color: 0xffffff, state.tvScreen.material = new THREE.ShaderMaterial({
map: state.videoTexture, uniforms: {
fog: false, videoTexture: { value: state.videoTexture }
lightMapIntensity: 0, },
reflectivity: 0 vertexShader: screenVertexShader,
fragmentShader: screenFragmentShader,
transparent: true,
}); });
state.tvScreen.material.needsUpdate = true; state.tvScreen.material.needsUpdate = true;
} }

View File

@ -0,0 +1,19 @@
export const screenVertexShader = `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
export const screenFragmentShader = `
varying vec2 vUv;
uniform sampler2D videoTexture;
void main() {
// Sample the video texture
gl_FragColor = texture2D(videoTexture, vUv);
}
`;