diff --git a/src/entities/CameraEntity.ts b/src/entities/CameraEntity.ts index 273d61a..e2be55a 100644 --- a/src/entities/CameraEntity.ts +++ b/src/entities/CameraEntity.ts @@ -12,6 +12,7 @@ import aoFrag from '../shaders/ao.frag'; import quadVert from '../shaders/quad.vert'; import shadingFrag from '../shaders/shading.frag'; import { gl } from '../heck/canvas'; +import { randomTexture } from '../utils/RandomTexture'; export interface CameraEntityOptions { root: Entity; @@ -19,7 +20,6 @@ export interface CameraEntityOptions { lights: LightEntity[]; textureIBLLUT: GLCatTexture; textureEnv: GLCatTexture; - textureRandom: GLCatTexture; } export class CameraEntity { @@ -95,7 +95,7 @@ export class CameraEntity { ); } - aoMaterial.addUniformTexture( 'samplerRandom', options.textureRandom ); + aoMaterial.addUniformTexture( 'samplerRandom', randomTexture.texture ); const aoQuad = new Quad( { material: aoMaterial, @@ -189,7 +189,7 @@ export class CameraEntity { shadingMaterial.addUniformTexture( 'samplerShadow', light.shadowMap.texture ); shadingMaterial.addUniformTexture( 'samplerIBLLUT', options.textureIBLLUT ); shadingMaterial.addUniformTexture( 'samplerEnv', options.textureEnv ); - shadingMaterial.addUniformTexture( 'samplerRandom', options.textureRandom ); + shadingMaterial.addUniformTexture( 'samplerRandom', randomTexture.texture ); const shadingQuad = new Quad( { material: shadingMaterial, diff --git a/src/entities/FlickyParticles.ts b/src/entities/FlickyParticles.ts index 003029b..c415f17 100644 --- a/src/entities/FlickyParticles.ts +++ b/src/entities/FlickyParticles.ts @@ -10,11 +10,10 @@ import flickyParticleRenderFrag from '../shaders/flicky-particles-render.frag'; import flickyParticleRenderVert from '../shaders/flicky-particles-render.vert'; import { TRIANGLE_STRIP_QUAD } from '@fms-cat/experimental'; import { gl, glCat } from '../heck/canvas'; +import { randomTexture, randomTextureStatic } from '../utils/RandomTexture'; export interface FlickyParticlesOptions { particlesSqrt: number; - textureRandom: GLCatTexture; - textureRandomStatic: GLCatTexture; } export class FlickyParticles { @@ -51,7 +50,7 @@ export class FlickyParticles { const material = new Material( quadVert, flickyParticleComputeFrag ); material.addUniform( 'particlesSqrt', '1f', particlesSqrt ); material.addUniform( 'particles', '1f', particles ); - material.addUniformTexture( 'samplerRandom', options.textureRandom ); + material.addUniformTexture( 'samplerRandom', randomTexture.texture ); if ( process.env.DEV ) { if ( module.hot ) { @@ -114,7 +113,7 @@ export class FlickyParticles { flickyParticleRenderFrag, ); material.addUniform( 'colorVar', '1f', 0.1 ); - material.addUniformTexture( 'samplerRandomStatic', options.textureRandomStatic ); + material.addUniformTexture( 'samplerRandomStatic', randomTextureStatic.texture ); if ( process.env.DEV ) { if ( module.hot ) { diff --git a/src/entities/Raymarcher.ts b/src/entities/Raymarcher.ts index 6bd46b1..5b5e955 100644 --- a/src/entities/Raymarcher.ts +++ b/src/entities/Raymarcher.ts @@ -8,6 +8,7 @@ import { Material } from '../heck/Material'; import quadVert from '../shaders/quad.vert'; import raymarcherFrag from '../shaders/raymarcher.frag'; import { Lambda } from '../heck/components/Lambda'; +import { randomTexture, randomTextureStatic } from '../utils/RandomTexture'; export class Raymarcher { private __mesh: Mesh; @@ -25,10 +26,7 @@ export class Raymarcher { return this.__entity; } - public constructor( options: { - textureRandom: GLCatTexture; - textureRandomStatic: GLCatTexture; - } ) { + public constructor() { this.__entity = new Entity(); this.__entity.transform.position = new Vector3( [ 0.0, 0.0, 0.3 ] ); this.__entity.transform.scale = new Vector3( [ 16.0, 9.0, 1.0 ] ).scale( 0.15 ); @@ -38,8 +36,8 @@ export class Raymarcher { this.__material.addUniform( 'range', '4f', -1.0, -1.0, 1.0, 1.0 ); - this.__material.addUniformTexture( 'samplerRandom', options.textureRandom ); - this.__material.addUniformTexture( 'samplerRandomStatic', options.textureRandomStatic ); + this.__material.addUniformTexture( 'samplerRandom', randomTexture.texture ); + this.__material.addUniformTexture( 'samplerRandomStatic', randomTextureStatic.texture ); this.__entity.components.push( new Lambda( { onDraw: ( event ) => { diff --git a/src/entities/SphereParticles.ts b/src/entities/SphereParticles.ts index 2f07163..f1e5d12 100644 --- a/src/entities/SphereParticles.ts +++ b/src/entities/SphereParticles.ts @@ -1,4 +1,3 @@ -import { GLCatTexture } from '@fms-cat/glcat-ts'; import { Entity } from '../heck/Entity'; import { GPUParticles } from './GPUParticles'; import { Geometry } from '../heck/Geometry'; @@ -10,11 +9,10 @@ import sphereParticleComputeFrag from '../shaders/sphere-particles-compute.frag' import sphereParticleRenderFrag from '../shaders/sphere-particles-render.frag'; import sphereParticleRenderVert from '../shaders/sphere-particles-render.vert'; import { gl, glCat } from '../heck/canvas'; +import { randomTexture, randomTextureStatic } from '../utils/RandomTexture'; export interface SphereParticlesOptions { particlesSqrt: number; - textureRandom: GLCatTexture; - textureRandomStatic: GLCatTexture; } export class SphereParticles { @@ -51,7 +49,7 @@ export class SphereParticles { const material = new Material( quadVert, sphereParticleComputeFrag ); material.addUniform( 'particlesSqrt', '1f', particlesSqrt ); material.addUniform( 'particles', '1f', particles ); - material.addUniformTexture( 'samplerRandom', options.textureRandom ); + material.addUniformTexture( 'samplerRandom', randomTexture.texture ); if ( process.env.DEV ) { if ( module.hot ) { @@ -117,7 +115,7 @@ export class SphereParticles { }, ); material.addUniform( 'colorVar', '1f', 0.1 ); - material.addUniformTexture( 'samplerRandomStatic', options.textureRandomStatic ); + material.addUniformTexture( 'samplerRandomStatic', randomTextureStatic.texture ); if ( process.env.DEV ) { if ( module.hot ) { diff --git a/src/entities/Trails.ts b/src/entities/Trails.ts index 61e9599..3d2da0c 100644 --- a/src/entities/Trails.ts +++ b/src/entities/Trails.ts @@ -1,4 +1,3 @@ -import { GLCatTexture } from '@fms-cat/glcat-ts'; import { Entity } from '../heck/Entity'; import { GPUParticles } from './GPUParticles'; import { Geometry } from '../heck/Geometry'; @@ -9,12 +8,11 @@ import trailsComputeFrag from '../shaders/trails-compute.frag'; import trailsRenderFrag from '../shaders/trails-render.frag'; import trailsRenderVert from '../shaders/trails-render.vert'; import { gl, glCat } from '../heck/canvas'; +import { randomTexture, randomTextureStatic } from '../utils/RandomTexture'; export interface TrailsOptions { trails: number; trailLength: number; - textureRandom: GLCatTexture; - textureRandomStatic: GLCatTexture; } export class Trails { @@ -48,7 +46,7 @@ export class Trails { const material = new Material( quadVert, trailsComputeFrag ); material.addUniform( 'trails', '1f', options.trails ); material.addUniform( 'trailLength', '1f', options.trailLength ); - material.addUniformTexture( 'samplerRandom', options.textureRandom ); + material.addUniformTexture( 'samplerRandom', randomTexture.texture ); if ( process.env.DEV ) { if ( module.hot ) { @@ -149,7 +147,7 @@ export class Trails { trailsRenderVert, trailsRenderFrag, ); - material.addUniformTexture( 'samplerRandomStatic', options.textureRandomStatic ); + material.addUniformTexture( 'samplerRandomStatic', randomTextureStatic.texture ); if ( process.env.DEV ) { if ( module.hot ) { diff --git a/src/main.ts b/src/main.ts index 9e34adc..8b8e66a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,8 +7,7 @@ import { canvas, glCat } from './heck/canvas'; import { Dog } from './heck/Dog'; import { CanvasRenderTarget } from './heck/CanvasRenderTarget'; import { Lambda } from './heck/components/Lambda'; -import { RandomTexture } from './utils/RandomTexture'; -import { RANDOM_RESOLUTION, STATIC_RANDOM_RESOLUTION } from './config'; +import { randomTexture } from './utils/RandomTexture'; import { SphereParticles } from './entities/SphereParticles'; import { Swap, Vector3 } from '@fms-cat/experimental'; import { BufferRenderTarget } from './heck/BufferRenderTarget'; @@ -163,21 +162,6 @@ if ( process.env.DEV ) { ); } -// == textures ===================================================================================== -const randomTexture = new RandomTexture( - glCat, - RANDOM_RESOLUTION[ 0 ], - RANDOM_RESOLUTION[ 1 ] -); -randomTexture.update(); - -const randomTextureStatic = new RandomTexture( - glCat, - STATIC_RANDOM_RESOLUTION[ 0 ], - STATIC_RANDOM_RESOLUTION[ 1 ] -); -randomTextureStatic.update(); - // == scene ======================================================================================== const dog = new Dog( music ); @@ -206,16 +190,12 @@ dog.root.children.push( environmentMap.entity ); // -- "objects" ------------------------------------------------------------------------------------ const sphereParticles = new SphereParticles( { particlesSqrt: 256, - textureRandom: randomTexture.texture, - textureRandomStatic: randomTextureStatic.texture } ); dog.root.children.push( sphereParticles.entity ); const trails = new Trails( { trails: 4096, trailLength: 64, - textureRandom: randomTexture.texture, - textureRandomStatic: randomTextureStatic.texture } ); dog.root.children.push( trails.entity ); @@ -227,15 +207,10 @@ dog.root.children.push( cube.entity ); const flickyParticles = new FlickyParticles( { particlesSqrt: 8, - textureRandom: randomTexture.texture, - textureRandomStatic: randomTextureStatic.texture, } ); dog.root.children.push( flickyParticles.entity ); -const raymarcher = new Raymarcher( { - textureRandom: randomTexture.texture, - textureRandomStatic: randomTextureStatic.texture -} ); +const raymarcher = new Raymarcher(); dog.root.children.push( raymarcher.entity ); // -- things that is not an "object" --------------------------------------------------------------- @@ -286,7 +261,6 @@ const camera = new CameraEntity( { ], textureIBLLUT: ibllut.texture, textureEnv: environmentMap.texture, - textureRandom: randomTexture.texture } ); camera.camera.clear = [ 0.0, 0.0, 0.0, 0.0 ]; camera.entity.components.unshift( new Lambda( { diff --git a/src/utils/RandomTexture.ts b/src/utils/RandomTexture.ts index dc26508..ac70afc 100644 --- a/src/utils/RandomTexture.ts +++ b/src/utils/RandomTexture.ts @@ -1,6 +1,7 @@ import { GLCat, GLCatTexture } from '@fms-cat/glcat-ts'; import { Xorshift } from '@fms-cat/experimental'; -import { gl } from '../heck/canvas'; +import { gl, glCat } from '../heck/canvas'; +import { RANDOM_RESOLUTION, STATIC_RANDOM_RESOLUTION } from '../config'; export class RandomTexture { private __texture: GLCatTexture; @@ -52,3 +53,17 @@ export class RandomTexture { ); } } + +export const randomTexture = new RandomTexture( + glCat, + RANDOM_RESOLUTION[ 0 ], + RANDOM_RESOLUTION[ 1 ] +); +randomTexture.update(); + +export const randomTextureStatic = new RandomTexture( + glCat, + STATIC_RANDOM_RESOLUTION[ 0 ], + STATIC_RANDOM_RESOLUTION[ 1 ] +); +randomTextureStatic.update();