Skip to content

Commit

Permalink
Fixes dynamic shader + shader manager (#89)
Browse files Browse the repository at this point in the history
Dynamic Shader

- Removed any uses to the Effect object, everything is now linked to the
active shader manager of the renderer.

Shader Manager

- Made the effect constructors available via the function
getRegisteredEffects()
- Made the shader constructors available via the function
getRegisteredShaders()
  • Loading branch information
frank-weindel authored Nov 30, 2023
2 parents cfc5b38 + bdcd76c commit 75d7acf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
8 changes: 8 additions & 0 deletions src/core/CoreShaderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export class CoreShaderManager {
this.effectConstructors[effectType] = effectClass;
}

getRegisteredEffects(): Partial<EffectMap> {
return this.effectConstructors;
}

getRegisteredShaders(): Partial<ShaderMap> {
return this.shConstructors;
}

loadShader<Type extends keyof ShaderMap>(
shType: Type,
props?: ExtractProps<ShaderMap[Type]>,
Expand Down
34 changes: 4 additions & 30 deletions src/core/renderers/webgl/shaders/DynamicShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,7 @@ import {
} from '../WebGlCoreShader.js';
import type { UniformInfo } from '../internal/ShaderUtils.js';
import type { WebGlCoreCtxTexture } from '../WebGlCoreCtxTexture.js';
import { RadiusEffect } from './effects/RadiusEffect.js';
import { BorderEffect } from './effects/BorderEffect.js';
import { LinearGradientEffect } from './effects/LinearGradientEffect.js';
import { GrayscaleEffect } from './effects/GrayscaleEffect.js';
import { ShaderEffect } from './effects/ShaderEffect.js';
import { BorderRightEffect } from './effects/BorderRightEffect.js';
import { BorderTopEffect } from './effects/BorderTopEffect.js';
import { BorderBottomEffect } from './effects/BorderBottomEffect.js';
import { BorderLeftEffect } from './effects/BorderLeftEffect.js';
import { GlitchEffect } from './effects/GlitchEffect.js';
import { FadeOutEffect } from './effects/FadeOutEffect.js';
import { RadialGradientEffect } from './effects/RadialGradientEffect.js';
import { RadialProgressEffect } from './effects/RadialProgressEffect.js';
import type { EffectMap } from '../../../CoreShaderManager.js';

/**
Expand Down Expand Up @@ -84,21 +72,6 @@ export interface DynamicShaderProps
effects?: EffectDesc[];
}

const Effects = {
radius: RadiusEffect,
border: BorderEffect,
borderBottom: BorderBottomEffect,
borderLeft: BorderLeftEffect,
borderRight: BorderRightEffect,
borderTop: BorderTopEffect,
fadeOut: FadeOutEffect,
linearGradient: LinearGradientEffect,
radialGradient: RadialGradientEffect,
grayscale: GrayscaleEffect,
glitch: GlitchEffect,
radialProgress: RadialProgressEffect,
};

export interface SpecificEffectDesc<
FxType extends keyof EffectMap = keyof EffectMap,
> {
Expand Down Expand Up @@ -144,9 +117,10 @@ export class DynamicShader extends WebGlCoreShader {
}

protected override bindProps(props: Required<DynamicShaderProps>): void {
const effects = this.renderer.shManager.getRegisteredEffects();
props.effects?.forEach((eff, index) => {
const effect = this.effects[index]!;
const fxClass = Effects[effect.name as keyof EffectMap];
const fxClass = effects[effect.name as keyof EffectMap]!;
const props = eff.props ?? {};
const uniInfo = effect.uniformInfo;
Object.keys(props).forEach((p) => {
Expand Down Expand Up @@ -296,7 +270,7 @@ export class DynamicShader extends WebGlCoreShader {
const current = effects[i]!;
const pm =
current.passParameters.length > 0 ? `, ${current.passParameters}` : '';
const currentClass = Effects[current.name as keyof EffectMap];
const currentClass = effectContructors[current.name as keyof EffectMap]!;

if (currentClass.onShaderMask) {
drawEffects += `
Expand All @@ -315,7 +289,7 @@ export class DynamicShader extends WebGlCoreShader {
const next = effects[i + 1]!;
if (
next === undefined ||
Effects[next.name as keyof EffectMap].onEffectMask
effectContructors[next.name as keyof EffectMap]!.onEffectMask
) {
drawEffects += `
shaderColor = ${currentMask};
Expand Down

0 comments on commit 75d7acf

Please sign in to comment.