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; const sixteenBarLength = 3840.0 / MUSIC_BPM;
program.attribute( 'off', this.__bufferOff, 1 ); program.attribute( 'off', this.__bufferOff, 1 );
program.uniform1f( 'bpm', MUSIC_BPM ); program.uniform( 'bpm', '1f', MUSIC_BPM );
program.uniform1f( 'bufferLength', MUSIC_BUFFER_LENGTH ); program.uniform( 'bufferLength', '1f', MUSIC_BUFFER_LENGTH );
program.uniform1f( '_deltaSample', 1.0 / this.audio.sampleRate ); program.uniform( '_deltaSample', '1f', 1.0 / this.audio.sampleRate );
program.uniform4f( program.uniform(
'timeLength', 'timeLength',
'4f',
beatLength, beatLength,
barLength, barLength,
sixteenBarLength, sixteenBarLength,
1E16 1E16
); );
program.uniform4f( program.uniform(
'_timeHead', '_timeHead',
'4f',
time % beatLength, time % beatLength,
time % barLength, time % barLength,
time % sixteenBarLength, time % sixteenBarLength,
time time,
); );
program.uniformTexture( 'samplerRandom', randomTextureStatic.texture ); program.uniformTexture( 'samplerRandom', randomTextureStatic.texture );

View File

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

View File

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

View File

@@ -2,8 +2,8 @@ import { Automaton } from '@fms-cat/automaton';
import { AutomatonWithGUI } from '@fms-cat/automaton-with-gui'; import { AutomatonWithGUI } from '@fms-cat/automaton-with-gui';
import { fxDefinitions } from '../automaton-fxs/fxDefinitions'; import { fxDefinitions } from '../automaton-fxs/fxDefinitions';
import { getDivAutomaton } from './dom'; import { getDivAutomaton } from './dom';
import { music } from './music';
import automatonData from '../automaton.json'; import automatonData from '../automaton.json';
import type { Music } from '../Music';
export const automaton = ( () => { export const automaton = ( () => {
if ( process.env.DEV ) { 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 ) { if ( module.hot ) {
module.hot.accept( '../automaton.json', () => { module.hot.accept( '../automaton.json', () => {
// we probably don't need this feature for now... // 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; export const auto = automaton.auto;

View File

@@ -1,5 +1,7 @@
import { Music } from '../Music'; import { Music } from '../Music';
import { automatonSetupMusic } from './automaton';
import { glCat } from './canvas'; import { glCat } from './canvas';
export const audio = new AudioContext(); export const audio = new AudioContext();
export const music = new Music( glCat, audio ); 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 { Geometry } from './Geometry';
import { RenderTarget } from './RenderTarget'; import { RenderTarget } from './RenderTarget';
import { SHADERPOOL } from './ShaderPool'; import { SHADERPOOL } from './ShaderPool';
@@ -31,11 +31,19 @@ export class Material {
protected __uniformVectors: { protected __uniformVectors: {
[ name: string ]: { [ name: string ]: {
type: GLCatProgramUniformType; type: GLCatProgramUniformVectorType;
value: Float32List | Int32List; value: Float32List | Int32List;
}; };
} = {}; } = {};
protected __uniformMatrixVectors: {
[ name: string ]: {
type: GLCatProgramUniformMatrixVectorType;
value: Float32List | Int32List;
transpose?: boolean;
};
} = {};
protected __uniformTextures: { protected __uniformTextures: {
[ name: string ]: { [ name: string ]: {
texture: GLCatTexture | null; texture: GLCatTexture | null;
@@ -109,12 +117,20 @@ export class Material {
public addUniformVector( public addUniformVector(
name: string, name: string,
type: GLCatProgramUniformType, type: GLCatProgramUniformVectorType,
value: Float32List | Int32List value: Float32List | Int32List
): void { ): void {
this.__uniformVectors[ name ] = { type, value }; 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 { public addUniformTexture( name: string, texture: GLCatTexture | null ): void {
this.__uniformTextures[ name ] = { texture }; this.__uniformTextures[ name ] = { texture };
} }
@@ -134,6 +150,12 @@ export class Material {
program.uniformVector( name, type, value ); 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 } ] ) => { Object.entries( this.__uniformTextures ).forEach( ( [ name, { texture } ] ) => {
program.uniformTexture( name, texture ); program.uniformTexture( name, texture );
} ); } );

View File

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

View File

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