fix: even more size coding on glcat-ts side

This commit is contained in:
FMS-Cat
2021-03-27 02:58:52 +09:00
parent 9af5b93be0
commit 33c4eb3f9f
8 changed files with 71 additions and 36 deletions

View File

@@ -251,22 +251,24 @@ export class Music {
const sixteenBarLength = 3840.0 / MUSIC_BPM;
program.attribute( 'off', this.__bufferOff, 1 );
program.uniform1f( 'bpm', MUSIC_BPM );
program.uniform1f( 'bufferLength', MUSIC_BUFFER_LENGTH );
program.uniform1f( '_deltaSample', 1.0 / this.audio.sampleRate );
program.uniform4f(
program.uniform( 'bpm', '1f', MUSIC_BPM );
program.uniform( 'bufferLength', '1f', MUSIC_BUFFER_LENGTH );
program.uniform( '_deltaSample', '1f', 1.0 / this.audio.sampleRate );
program.uniform(
'timeLength',
'4f',
beatLength,
barLength,
sixteenBarLength,
1E16
);
program.uniform4f(
program.uniform(
'_timeHead',
'4f',
time % beatLength,
time % barLength,
time % sixteenBarLength,
time
time,
);
program.uniformTexture( 'samplerRandom', randomTextureStatic.texture );

View File

@@ -65,7 +65,7 @@ export class CameraEntity extends Entity {
onUpdate: () => {
const cameraView = this.transform.matrix.inverse!;
aoMaterial.addUniformVector(
aoMaterial.addUniformMatrixVector(
'cameraPV',
'Matrix4fv',
this.camera.projectionMatrix.multiply(
@@ -118,13 +118,13 @@ export class CameraEntity extends Entity {
const cameraView = this.transform.matrix.inverse!;
shadingMaterial.addUniformVector(
shadingMaterial.addUniformMatrixVector(
'cameraView',
'Matrix4fv',
cameraView.elements
);
shadingMaterial.addUniformVector(
shadingMaterial.addUniformMatrixVector(
'cameraPV',
'Matrix4fv',
this.camera.projectionMatrix.multiply(
@@ -164,7 +164,7 @@ export class CameraEntity extends Entity {
...light.color
);
shadingMaterial.addUniformVector(
shadingMaterial.addUniformMatrixVector(
'lightPV',
'Matrix4fv',
light.camera.projectionMatrix.multiply(

View File

@@ -79,7 +79,7 @@ export class Raymarcher extends Entity {
event.camera.far
);
material.addUniformVector(
material.addUniformMatrixVector(
'inversePVM',
'Matrix4fv',
event.projectionMatrix

View File

@@ -2,8 +2,8 @@ import { Automaton } from '@fms-cat/automaton';
import { AutomatonWithGUI } from '@fms-cat/automaton-with-gui';
import { fxDefinitions } from '../automaton-fxs/fxDefinitions';
import { getDivAutomaton } from './dom';
import { music } from './music';
import automatonData from '../automaton.json';
import type { Music } from '../Music';
export const automaton = ( () => {
if ( process.env.DEV ) {
@@ -18,13 +18,6 @@ export const automaton = ( () => {
},
);
automatonWithGUI.on( 'play', () => { music.isPlaying = true; } );
automatonWithGUI.on( 'pause', () => { music.isPlaying = false; } );
automatonWithGUI.on( 'seek', ( { time } ) => {
music.time = Math.max( 0.0, time );
automatonWithGUI.reset();
} );
if ( module.hot ) {
module.hot.accept( '../automaton.json', () => {
// we probably don't need this feature for now...
@@ -44,4 +37,20 @@ export const automaton = ( () => {
}
} )();
/**
* Since automaton and music try to reference each other...
*/
export function automatonSetupMusic( music: Music ): void {
if ( process.env.DEV ) {
const automatonWithGUI = automaton as AutomatonWithGUI;
automatonWithGUI.on( 'play', () => { music.isPlaying = true; } );
automatonWithGUI.on( 'pause', () => { music.isPlaying = false; } );
automatonWithGUI.on( 'seek', ( { time } ) => {
music.time = Math.max( 0.0, time );
automatonWithGUI.reset();
} );
}
}
export const auto = automaton.auto;

View File

@@ -1,5 +1,7 @@
import { Music } from '../Music';
import { automatonSetupMusic } from './automaton';
import { glCat } from './canvas';
export const audio = new AudioContext();
export const music = new Music( glCat, audio );
automatonSetupMusic( music );

View File

@@ -1,4 +1,4 @@
import { GLCatProgram, GLCatProgramLinkOptions, GLCatProgramUniformType, GLCatTexture, GLCatTextureCubemap } from '@fms-cat/glcat-ts';
import { GLCatProgram, GLCatProgramLinkOptions, GLCatProgramUniformMatrixVectorType, GLCatProgramUniformType, GLCatProgramUniformVectorType, GLCatTexture, GLCatTextureCubemap } from '@fms-cat/glcat-ts';
import { Geometry } from './Geometry';
import { RenderTarget } from './RenderTarget';
import { SHADERPOOL } from './ShaderPool';
@@ -31,11 +31,19 @@ export class Material {
protected __uniformVectors: {
[ name: string ]: {
type: GLCatProgramUniformType;
type: GLCatProgramUniformVectorType;
value: Float32List | Int32List;
};
} = {};
protected __uniformMatrixVectors: {
[ name: string ]: {
type: GLCatProgramUniformMatrixVectorType;
value: Float32List | Int32List;
transpose?: boolean;
};
} = {};
protected __uniformTextures: {
[ name: string ]: {
texture: GLCatTexture | null;
@@ -109,12 +117,20 @@ export class Material {
public addUniformVector(
name: string,
type: GLCatProgramUniformType,
type: GLCatProgramUniformVectorType,
value: Float32List | Int32List
): void {
this.__uniformVectors[ name ] = { type, value };
}
public addUniformMatrixVector(
name: string,
type: GLCatProgramUniformMatrixVectorType,
value: Float32List | Int32List
): void {
this.__uniformMatrixVectors[ name ] = { type, value };
}
public addUniformTexture( name: string, texture: GLCatTexture | null ): void {
this.__uniformTextures[ name ] = { texture };
}
@@ -134,6 +150,12 @@ export class Material {
program.uniformVector( name, type, value );
} );
Object.entries( this.__uniformMatrixVectors ).forEach(
( [ name, { type, value, transpose } ] ) => {
program.uniformMatrixVector( name, type, value, transpose );
}
);
Object.entries( this.__uniformTextures ).forEach( ( [ name, { texture } ] ) => {
program.uniformTexture( name, texture );
} );

View File

@@ -58,16 +58,16 @@ export class Mesh extends Component {
material.setUniforms();
program.uniform1f( 'time', event.time );
program.uniform1f( 'frameCount', event.frameCount );
program.uniform2f( 'resolution', event.renderTarget.width, event.renderTarget.height );
program.uniform3f( 'cameraPos', ...event.cameraTransform.position.elements );
program.uniform2f( 'cameraNearFar', event.camera.near, event.camera.far );
program.uniform( 'time', '1f', event.time );
program.uniform( 'frameCount', '1f', event.frameCount );
program.uniform( 'resolution', '2f', event.renderTarget.width, event.renderTarget.height );
program.uniform( 'cameraPos', '3f', ...event.cameraTransform.position.elements );
program.uniform( 'cameraNearFar', '2f', event.camera.near, event.camera.far );
program.uniformMatrix4fv( 'normalMatrix', event.globalTransform.matrix.inverse!.transpose.elements );
program.uniformMatrix4fv( 'modelMatrix', event.globalTransform.matrix.elements );
program.uniformMatrix4fv( 'viewMatrix', event.viewMatrix.elements );
program.uniformMatrix4fv( 'projectionMatrix', event.projectionMatrix.elements );
program.uniformMatrixVector( 'normalMatrix', 'Matrix4fv', event.globalTransform.matrix.inverse!.transpose.elements );
program.uniformMatrixVector( 'modelMatrix', 'Matrix4fv', event.globalTransform.matrix.elements );
program.uniformMatrixVector( 'viewMatrix', 'Matrix4fv', event.viewMatrix.elements );
program.uniformMatrixVector( 'projectionMatrix', 'Matrix4fv', event.projectionMatrix.elements );
this.geometry.draw();
}

View File

@@ -45,11 +45,11 @@ export class Quad extends Component {
const program = this.material.program;
program.uniform1f( 'time', event.time );
program.uniform1f( 'deltaTime', event.deltaTime );
program.uniform1f( 'frameCount', event.frameCount );
program.uniform2f( 'resolution', this.target.width, this.target.height );
program.uniform4f( 'range', ...this.range );
program.uniform( 'time', '1f', event.time );
program.uniform( 'deltaTime', '1f', event.deltaTime );
program.uniform( 'frameCount', '1f', event.frameCount );
program.uniform( 'resolution', '2f', this.target.width, this.target.height );
program.uniform( 'range', '4f', ...this.range );
quadGeometry.draw();
}