Skip to content

Renamed internal class ShaderUtils to ShaderDefinitionUtils #7652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ const _attrib2Semantic = {
};

/**
* A class providing utility functions for shader creation.
* A class providing utility functions for shader definition creation.
*
* @ignore
*/
class ShaderUtils {
class ShaderDefinitionUtils {
/**
* Creates a shader definition.
*
Expand Down Expand Up @@ -110,8 +110,8 @@ class ShaderUtils {
let vertCode;
let fragCode;

const vertexDefinesCode = ShaderUtils.getDefinesCode(device, options.vertexDefines);
const fragmentDefinesCode = ShaderUtils.getDefinesCode(device, options.fragmentDefines);
const vertexDefinesCode = ShaderDefinitionUtils.getDefinesCode(device, options.vertexDefines);
const fragmentDefinesCode = ShaderDefinitionUtils.getDefinesCode(device, options.fragmentDefines);
const wgsl = options.shaderLanguage === SHADERLANGUAGE_WGSL;

if (wgsl) {
Expand All @@ -133,22 +133,22 @@ class ShaderUtils {
} else {

// vertex code
vertCode = `${ShaderUtils.versionCode(device) +
vertCode = `${ShaderDefinitionUtils.versionCode(device) +
getDefines(webgpuVS, gles3VS, true, options) +
vertexDefinesCode +
ShaderUtils.precisionCode(device)}
ShaderDefinitionUtils.precisionCode(device)}
${sharedGLSL}
${ShaderUtils.getShaderNameCode(name)}
${ShaderDefinitionUtils.getShaderNameCode(name)}
${options.vertexCode}`;

// fragment code
fragCode = `${(options.fragmentPreamble || '') +
ShaderUtils.versionCode(device) +
ShaderDefinitionUtils.versionCode(device) +
getDefines(webgpuFS, gles3FS, false, options) +
fragmentDefinesCode +
ShaderUtils.precisionCode(device)}
ShaderDefinitionUtils.precisionCode(device)}
${sharedGLSL}
${ShaderUtils.getShaderNameCode(name)}
${ShaderDefinitionUtils.getShaderNameCode(name)}
${options.fragmentCode}`;
}

Expand Down Expand Up @@ -279,4 +279,4 @@ class ShaderUtils {
}
}

export { ShaderUtils };
export { ShaderDefinitionUtils };
4 changes: 2 additions & 2 deletions src/platform/graphics/shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { platform } from '../../core/platform.js';
import { Preprocessor } from '../../core/preprocessor.js';
import { SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL } from './constants.js';
import { DebugGraphics } from './debug-graphics.js';
import { ShaderUtils } from './shader-utils.js';
import { ShaderDefinitionUtils } from './shader-definition-utils.js';

/**
* @import { BindGroupFormat } from './bind-group-format.js'
Expand Down Expand Up @@ -143,7 +143,7 @@ class Shader {

// if no attributes are specified, try to extract the default names after the shader has been pre-processed
if (definition.shaderLanguage === SHADERLANGUAGE_GLSL) {
definition.attributes ??= ShaderUtils.collectAttributes(definition.vshader);
definition.attributes ??= ShaderDefinitionUtils.collectAttributes(definition.vshader);
}

// Strip unused color attachments from fragment shader.
Expand Down
4 changes: 2 additions & 2 deletions src/platform/graphics/transform-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BUFFER_GPUDYNAMIC, PRIMITIVE_POINTS } from './constants.js';
import { VertexBuffer } from './vertex-buffer.js';
import { DebugGraphics } from './debug-graphics.js';
import { Shader } from './shader.js';
import { ShaderUtils } from './shader-utils.js';
import { ShaderDefinitionUtils } from './shader-definition-utils.js';

/**
* @import { GraphicsDevice } from './graphics-device.js'
Expand Down Expand Up @@ -120,7 +120,7 @@ class TransformFeedback {
* @returns {Shader} A shader to use in the process() function.
*/
static createShader(graphicsDevice, vertexCode, name) {
return new Shader(graphicsDevice, ShaderUtils.createDefinition(graphicsDevice, {
return new Shader(graphicsDevice, ShaderDefinitionUtils.createDefinition(graphicsDevice, {
name,
vertexCode,
useTransformFeedback: true,
Expand Down
2 changes: 1 addition & 1 deletion src/scene/materials/shader-material.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Material } from './material.js';
* inputs to the shader. Defaults to undefined, which generates the default attributes.
* @property {string | string[]} [fragmentOutputTypes] - Fragment shader output types, which default to
* vec4. Passing a string will set the output type for all color attachments. Passing an array will
* set the output type for each color attachment. @see ShaderUtils.createDefinition
* set the output type for each color attachment. @see ShaderDefinitionUtils.createDefinition
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions src/scene/shader-lib/programs/lit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LitShader } from './lit-shader.js';
import { LitOptionsUtils } from './lit-options-utils.js';
import { ShaderGenerator } from './shader-generator.js';
import { SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL, SHADERTAG_MATERIAL } from '../../../platform/graphics/constants.js';
import { ShaderUtils } from '../../../platform/graphics/shader-utils.js';
import { ShaderDefinitionUtils } from '../../../platform/graphics/shader-definition-utils.js';
import { hashCode } from '../../../core/hash.js';

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ class ShaderGeneratorLit extends ShaderGenerator {
definitionOptions.fragmentIncludes = includes;
definitionOptions.fragmentDefines = fDefines;

return ShaderUtils.createDefinition(device, definitionOptions);
return ShaderDefinitionUtils.createDefinition(device, definitionOptions);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/scene/shader-lib/programs/particle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SEMANTIC_POSITION, SEMANTIC_TEXCOORD0, SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL } from '../../../platform/graphics/constants.js';
import { ShaderUtils } from '../../../platform/graphics/shader-utils.js';
import { ShaderDefinitionUtils } from '../../../platform/graphics/shader-definition-utils.js';
import { blendNames } from '../../constants.js';
import { shaderChunksWGSL } from '../chunks-wgsl/chunks-wgsl.js';
import { shaderChunks } from '../chunks/chunks.js';
Expand Down Expand Up @@ -81,7 +81,7 @@ class ShaderGeneratorParticle extends ShaderGenerator {
...options.chunks
}));

return ShaderUtils.createDefinition(device, {
return ShaderDefinitionUtils.createDefinition(device, {
name: 'ParticleShader',
shaderLanguage: shaderLanguage,
attributes: attributes,
Expand Down
4 changes: 2 additions & 2 deletions src/scene/shader-lib/programs/shader-generator-shader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { hashCode } from '../../../core/hash.js';
import { SEMANTIC_ATTR15, SEMANTIC_BLENDINDICES, SEMANTIC_BLENDWEIGHT, SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL } from '../../../platform/graphics/constants.js';
import { ShaderUtils } from '../../../platform/graphics/shader-utils.js';
import { ShaderDefinitionUtils } from '../../../platform/graphics/shader-definition-utils.js';
import { shaderChunksWGSL } from '../chunks-wgsl/chunks-wgsl.js';
import { shaderChunks } from '../chunks/chunks.js';
import { ShaderGenerator } from './shader-generator.js';
Expand Down Expand Up @@ -105,7 +105,7 @@ class ShaderGeneratorShader extends ShaderGenerator {
this.createVertexDefinition(definitionOptions, options, sharedIncludes, wgsl);
this.createFragmentDefinition(definitionOptions, options, sharedIncludes, wgsl);

return ShaderUtils.createDefinition(device, definitionOptions);
return ShaderDefinitionUtils.createDefinition(device, definitionOptions);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/scene/shader-lib/programs/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ChunkUtils } from '../chunk-utils.js';
import { StandardMaterialOptions } from '../../materials/standard-material-options.js';
import { LitOptionsUtils } from './lit-options-utils.js';
import { ShaderGenerator } from './shader-generator.js';
import { ShaderUtils } from '../../../platform/graphics/shader-utils.js';
import { ShaderDefinitionUtils } from '../../../platform/graphics/shader-definition-utils.js';
import { SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL, SHADERTAG_MATERIAL } from '../../../platform/graphics/constants.js';

/**
Expand Down Expand Up @@ -445,7 +445,7 @@ class ShaderGeneratorStandard extends ShaderGenerator {

options.defines.forEach((value, key) => fDefines.set(key, value));

const definition = ShaderUtils.createDefinition(device, {
const definition = ShaderDefinitionUtils.createDefinition(device, {
name: 'StandardShader',
attributes: litShader.attributes,
shaderLanguage: shaderLanguage,
Expand Down
10 changes: 5 additions & 5 deletions src/scene/shader-lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Shader } from '../../platform/graphics/shader.js';
import { ShaderUtils } from '../../platform/graphics/shader-utils.js';
import { ShaderDefinitionUtils } from '../../platform/graphics/shader-definition-utils.js';
import { shaderChunks } from './chunks/chunks.js';
import { getProgramLibrary } from './get-program-library.js';
import { Debug } from '../../core/debug.js';
Expand Down Expand Up @@ -28,7 +28,7 @@ import { ShaderPass } from '../shader-pass.js';
* @param {string | string[]} [shaderDefinitionOptions.fragmentOutputTypes] - Fragment shader
* output types, which default to vec4. Passing a string will set the output type for all color
* attachments. Passing an array will set the output type for each color attachment.
* @see ShaderUtils.createDefinition
* @see ShaderDefinitionUtils.createDefinition
* @returns {Shader} The newly created shader.
* @category Graphics
*/
Expand All @@ -44,7 +44,7 @@ function createShader(device, vsName, fsName, useTransformFeedback = false, shad
};
}

return new Shader(device, ShaderUtils.createDefinition(device, {
return new Shader(device, ShaderDefinitionUtils.createDefinition(device, {
...shaderDefinitionOptions,
name: `${vsName}_${fsName}`,
vertexCode: shaderChunks[vsName],
Expand Down Expand Up @@ -75,7 +75,7 @@ function createShader(device, vsName, fsName, useTransformFeedback = false, shad
* @param {string | string[]} [shaderDefinitionOptions.fragmentOutputTypes] - Fragment shader
* output types, which default to vec4. Passing a string will set the output type for all color
* attachments. Passing an array will set the output type for each color attachment.
* @see ShaderUtils.createDefinition
* @see ShaderDefinitionUtils.createDefinition
* @returns {Shader} The newly created shader.
* @category Graphics
*/
Expand All @@ -97,7 +97,7 @@ function createShaderFromCode(device, vsCode, fsCode, uniqueName, attributes, us
const programLibrary = getProgramLibrary(device);
let shader = programLibrary.getCachedShader(uniqueName);
if (!shader) {
shader = new Shader(device, ShaderUtils.createDefinition(device, {
shader = new Shader(device, ShaderDefinitionUtils.createDefinition(device, {
...shaderDefinitionOptions,
name: uniqueName,
vertexCode: vsCode,
Expand Down