Skip to content

Commit

Permalink
Fixing for IShaderPath
Browse files Browse the repository at this point in the history
  • Loading branch information
RaananW committed Mar 28, 2024
1 parent e9f0c00 commit 6b2def1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2924,7 +2924,7 @@ export class ThinEngine {
* @returns the new Effect
*/
public createEffect(
baseName: IShaderPath & { vertexToken?: string; fragmentToken?: string },
baseName: string | (IShaderPath & { vertexToken?: string; fragmentToken?: string }),
attributesNamesOrOptions: string[] | IEffectCreationOptions,
uniformsNamesOrEngine: string[] | ThinEngine,
samplers?: string[],
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ export class WebGPUEngine extends Engine {
* @returns the new Effect
*/
public createEffect(
baseName: IShaderPath & { vertexToken?: string; fragmentToken?: string },
baseName: string | (IShaderPath & { vertexToken?: string; fragmentToken?: string }),
attributesNamesOrOptions: string[] | IEffectCreationOptions,
uniformsNamesOrEngine: string[] | Engine,
samplers?: string[],
Expand Down
62 changes: 30 additions & 32 deletions packages/dev/core/src/Materials/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,34 @@ import type { PostProcess } from "../PostProcesses/postProcess";
* * object: `{ vertex: "custom", fragment: "custom" }`, used with `Effect.ShadersStore["customVertexShader"]` and `Effect.ShadersStore["customFragmentShader"]`
* * string: `"./COMMON_NAME"`, used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.
*/
export type IShaderPath =
| {
/**
* Directly pass the shader code
*/
vertexSource?: string;
/**
* Directly pass the shader code
*/
fragmentSource?: string;
/**
* Used with Effect.ShadersStore. If the `vertex` is set to `"custom`, then
* Babylon.js will read from Effect.ShadersStore["customVertexShader"]
*/
vertex?: string;
/**
* Used with Effect.ShadersStore. If the `fragment` is set to `"custom`, then
* Babylon.js will read from Effect.ShadersStore["customFragmentShader"]
*/
fragment?: string;
/**
* Used with shader code in script tags
*/
vertexElement?: string;
/**
* Used with shader code in script tags
*/
fragmentElement?: string;
}
| string;
export type IShaderPath = {
/**
* Directly pass the shader code
*/
vertexSource?: string;
/**
* Directly pass the shader code
*/
fragmentSource?: string;
/**
* Used with Effect.ShadersStore. If the `vertex` is set to `"custom`, then
* Babylon.js will read from Effect.ShadersStore["customVertexShader"]
*/
vertex?: string;
/**
* Used with Effect.ShadersStore. If the `fragment` is set to `"custom`, then
* Babylon.js will read from Effect.ShadersStore["customFragmentShader"]
*/
fragment?: string;
/**
* Used with shader code in script tags
*/
vertexElement?: string;
/**
* Used with shader code in script tags
*/
fragmentElement?: string;
};

/**
* Options to be used when creating an effect.
Expand Down Expand Up @@ -145,7 +143,7 @@ export class Effect implements IDisposable {
/**
* Name of the effect.
*/
public name: IShaderPath;
public name: IShaderPath | string;
/**
* String container all the define statements that should be set on the shader.
*/
Expand Down Expand Up @@ -275,7 +273,7 @@ export class Effect implements IDisposable {
* @param shaderLanguage the language the shader is written in (default: GLSL)
*/
constructor(
baseName: IShaderPath,
baseName: IShaderPath | string,
attributesNamesOrOptions: string[] | IEffectCreationOptions,
uniformsNamesOrEngine: string[] | ThinEngine,
samplers: Nullable<string[]> = null,
Expand Down
8 changes: 4 additions & 4 deletions packages/dev/core/src/Materials/shaderMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export interface IShaderMaterialOptions {
* @see https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/shaderMaterial
*/
export class ShaderMaterial extends PushMaterial {
private _shaderPath: IShaderPath;
private _shaderPath: IShaderPath | string;
private _options: IShaderMaterialOptions;
private _textures: { [name: string]: BaseTexture } = {};
private _textureArrays: { [name: string]: BaseTexture[] } = {};
Expand Down Expand Up @@ -162,7 +162,7 @@ export class ShaderMaterial extends PushMaterial {
* @param options Define the options used to create the shader
* @param storeEffectOnSubMeshes true to store effect on submeshes, false to store the effect directly in the material class.
*/
constructor(name: string, scene: Scene, shaderPath: IShaderPath, options: Partial<IShaderMaterialOptions> = {}, storeEffectOnSubMeshes = true) {
constructor(name: string, scene: Scene, shaderPath: IShaderPath | string, options: Partial<IShaderMaterialOptions> = {}, storeEffectOnSubMeshes = true) {
super(name, scene, storeEffectOnSubMeshes);
this._shaderPath = shaderPath;

Expand All @@ -186,15 +186,15 @@ export class ShaderMaterial extends PushMaterial {
* Gets the shader path used to define the shader code
* It can be modified to trigger a new compilation
*/
public get shaderPath(): IShaderPath {
public get shaderPath() {
return this._shaderPath;
}

/**
* Sets the shader path used to define the shader code
* It can be modified to trigger a new compilation
*/
public set shaderPath(shaderPath: IShaderPath) {
public set shaderPath(shaderPath: IShaderPath | string) {
this._shaderPath = shaderPath;
}

Expand Down

0 comments on commit 6b2def1

Please sign in to comment.