UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

85 lines (84 loc) 4.9 kB
/** * @import { GraphicsDevice } from '../../platform/graphics/graphics-device.js' * @import { ShaderProcessorOptions } from '../../platform/graphics/shader-processor-options.js' * @import { CameraShaderParams } from '../camera-shader-params.js' * @import { Material, ShaderVariantParams } from '../materials/material.js' */ /** * Create a shader from named shader chunks. * * @param {GraphicsDevice} device - The graphics device. * @param {string} vsName - The vertex shader chunk name. * @param {string} fsName - The fragment shader chunk name. * @param {boolean | Record<string, boolean | string | string[]>} [useTransformFeedback] - Whether * to use transform feedback. Defaults to false. * @param {object} [shaderDefinitionOptions] - Additional options that will be added to the shader * definition. * @param {boolean} [shaderDefinitionOptions.useTransformFeedback] - Whether to use transform * feedback. Defaults to false. * @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 * @returns {Shader} The newly created shader. * @category Graphics */ export function createShader(device: GraphicsDevice, vsName: string, fsName: string, useTransformFeedback?: boolean | Record<string, boolean | string | string[]>, shaderDefinitionOptions?: { useTransformFeedback?: boolean; fragmentOutputTypes?: string | string[]; }): Shader; /** * Create a shader from the supplied source code. Note that this function adds additional shader * blocks to both vertex and fragment shaders, which allow the shader to use more features and * compile on both WebGL and WebGPU. Specifically, these blocks are added, and should not be * part of provided vsCode and fsCode: shader version, shader precision, commonly used extensions. * * @param {GraphicsDevice} device - The graphics device. * @param {string} vsCode - The vertex shader code. * @param {string} fsCode - The fragment shader code. * @param {string} uniqueName - Unique name for the shader. If a shader with this name already * exists, it will be returned instead of a new shader instance. * @param {Object<string, string>} [attributes] - Object detailing the mapping of vertex shader * attribute names to semantics SEMANTIC_*. This enables the engine to match vertex buffer data as * inputs to the shader. Defaults to undefined, which generates the default attributes. * @param {boolean | Record<string, boolean | string | string[]>} [useTransformFeedback] - Whether * to use transform feedback. Defaults to false. * @param {object} [shaderDefinitionOptions] - Additional options that will be added to the shader * definition. * @param {boolean} [shaderDefinitionOptions.useTransformFeedback] - Whether to use transform * feedback. Defaults to false. * @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 * @returns {Shader} The newly created shader. * @category Graphics */ export function createShaderFromCode(device: GraphicsDevice, vsCode: string, fsCode: string, uniqueName: string, attributes?: { [x: string]: string; }, useTransformFeedback?: boolean | Record<string, boolean | string | string[]>, shaderDefinitionOptions?: { useTransformFeedback?: boolean; fragmentOutputTypes?: string | string[]; }): Shader; /** * Process shader using shader processing options, utilizing cache of the ProgramLibrary * * @param {Shader} shader - The shader to be processed. * @param {ShaderProcessorOptions} processingOptions - The shader processing options. * @returns {Shader} The processed shader. */ export function processShader(shader: Shader, processingOptions: ShaderProcessorOptions): Shader; /** * Create a map of defines used for shader generation for a material. * * @param {Material} material - The material to create the shader defines for. * @param {ShaderVariantParams} params - The shader variant parameters. * @returns {Map<string, string>} The map of shader defines. * @ignore */ export function getCoreDefines(material: Material, params: ShaderVariantParams): Map<string, string>; import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js'; import { Shader } from '../../platform/graphics/shader.js'; import type { ShaderProcessorOptions } from '../../platform/graphics/shader-processor-options.js'; import type { Material } from '../materials/material.js'; import type { ShaderVariantParams } from '../materials/material.js';