|
| 1 | +/** |
| 2 | + * Cyber Descent - Main Effect Class |
| 3 | + * Implements the Cyber Descent effect using WebGL |
| 4 | + */ |
| 5 | +import { WebGLEffect } from "../../common/webgl-effect"; |
| 6 | +import { CyberDescentControls } from "./types"; |
| 7 | +import { |
| 8 | + getCyberDescentControls, |
| 9 | + initializeCyberDescentControls, |
| 10 | +} from "./utils"; |
| 11 | +import * as THREE from "three"; |
| 12 | + |
| 13 | +// Import shader code |
| 14 | +import fragmentShader from "./fragment.glsl"; |
| 15 | + |
| 16 | +/** |
| 17 | + * Cyber Descent effect implementation using WebGL/Three.js |
| 18 | + */ |
| 19 | +export class CyberDescentEffect extends WebGLEffect<CyberDescentControls> { |
| 20 | + constructor() { |
| 21 | + super({ |
| 22 | + id: "cyber-descent", |
| 23 | + name: "Cyber Descent", |
| 24 | + debug: true, // Enable debug mode |
| 25 | + fragmentShader, |
| 26 | + }); |
| 27 | + |
| 28 | + // Add direct console log to verify constructor is called |
| 29 | + console.log("👋 CyberDescentEffect constructor called"); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Initialize the controls and their default values |
| 34 | + */ |
| 35 | + protected initializeControls(): void { |
| 36 | + console.log("🎛️ Initializing controls"); |
| 37 | + initializeCyberDescentControls(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Get current control values from global scope |
| 42 | + */ |
| 43 | + protected getControlValues(): CyberDescentControls { |
| 44 | + return getCyberDescentControls(); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Apply control values to the effect parameters |
| 49 | + */ |
| 50 | + protected updateParameters(controls: CyberDescentControls): void { |
| 51 | + // Update uniforms is handled by the updateUniforms method |
| 52 | + super.updateParameters(controls); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Create the uniforms for the shader |
| 57 | + */ |
| 58 | + protected createUniforms(): Record<string, THREE.IUniform> { |
| 59 | + return { |
| 60 | + iSpeed: { value: 1.0 }, |
| 61 | + iZoom: { value: 1.0 }, |
| 62 | + iCyberpunkMode: { value: 0 }, |
| 63 | + iFogDensity: { value: 1.0 }, |
| 64 | + iLightIntensity: { value: 1.0 }, |
| 65 | + iColorSaturation: { value: 1.0 }, |
| 66 | + iColorIntensity: { value: 1.0 }, |
| 67 | + }; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Update the shader uniforms with current control values |
| 72 | + */ |
| 73 | + protected updateUniforms(controls: CyberDescentControls): void { |
| 74 | + if (!this.material) { |
| 75 | + this.debug("error", "Material not available for updating uniforms"); |
| 76 | + return; |
| 77 | + } |
| 78 | + |
| 79 | + // Update all uniform values based on controls |
| 80 | + this.material.uniforms.iSpeed.value = controls.speed; |
| 81 | + this.material.uniforms.iZoom.value = controls.zoom; |
| 82 | + this.material.uniforms.iCyberpunkMode.value = controls.cyberpunkMode; |
| 83 | + this.material.uniforms.iFogDensity.value = controls.fogDensity; |
| 84 | + this.material.uniforms.iLightIntensity.value = controls.lightIntensity; |
| 85 | + this.material.uniforms.iColorSaturation.value = controls.colorSaturation; |
| 86 | + this.material.uniforms.iColorIntensity.value = controls.colorIntensity; |
| 87 | + } |
| 88 | +} |
0 commit comments