import { Dict, UnionToIntersection } from './core/type'; import { mat2, mat3, mat4, vec2, vec3, vec4 } from './glmatrix'; import Texture2D from './Texture2D'; import Texture2DArray from './Texture2DArray'; import Texture3D from './Texture3D'; import TextureCube from './TextureCube'; export type ShaderDefineValue = boolean | string | number | undefined | null; export type ShaderPrecision = 'highp' | 'lowp' | 'mediump'; export type ShaderType = 'vertex' | 'fragment'; export type UniformType = 'bool' | 'int' | 'sampler2D' | 'sampler2DArray' | 'sampler3D' | 'samplerCube' | 'isampler2D' | 'usampler2D' | 'float' | 'vec2' | 'vec3' | 'vec4' | 'ivec2' | 'ivec3' | 'ivec4' | 'mat2' | 'mat3' | 'mat4'; export type NativeUniformType = Exclude; declare const attributeSizeMap: { readonly vec2: 2; readonly vec3: 3; readonly vec4: 4; readonly ivec2: 2; readonly ivec3: 3; readonly ivec4: 4; readonly float: 1; readonly int: 1; }; type NativeUniformValueMap = { bool: number; int: number; sampler2D: Texture2D; samplerCube: TextureCube; sampler3D: Texture3D; sampler2DArray: Texture2DArray; isampler2D: Texture2D; usampler2D: Texture2D; float: number; vec2: vec2.Vec2Array; vec3: vec3.Vec3Array; vec4: vec4.Vec4Array; ivec2: vec2.Vec2Array; ivec3: vec3.Vec3Array; ivec4: vec4.Vec4Array; mat2: mat2.Mat2Array; mat3: mat3.Mat3Array; mat4: mat4.Mat4Array; }; type NativeUniformArrayValueMap = { bool: ArrayLike; int: ArrayLike; sampler2D: Texture2D[]; samplerCube: TextureCube[]; sampler3D: Texture3D[]; sampler2DArray: Texture2DArray[]; isampler2D: Texture2D[]; usampler2D: Texture2D[]; float: ArrayLike; vec2: ArrayLike; vec3: ArrayLike; vec4: ArrayLike; ivec2: ArrayLike; ivec3: ArrayLike; ivec4: ArrayLike; mat2: ArrayLike; mat3: ArrayLike; mat4: ArrayLike; }; type NativeAttributeType = keyof typeof attributeSizeMap; export type AttributeSemantic = 'POSITION' | 'NORMAL' | 'BINORMAL' | 'TANGENT' | 'TEXCOORD_0' | 'TEXCOORD_1' | 'COLOR' | 'JOINT' | 'WEIGHT'; export type UniformSemantic = 'VIEWPORT_SIZE' | 'VIEWPORT' | 'DEVICEPIXELRATIO' | 'WINDOW_SIZE' | 'NEAR' | 'FAR' | 'TIME' | 'LOG_DEPTH_BUFFER_FC'; export declare const BASIC_MATRIX_SEMANTICS: readonly ["WORLD", "VIEW", "PROJECTION", "WORLDVIEW", "VIEWPROJECTION", "WORLDVIEWPROJECTION"]; type MatrixSemanticNoTranpose = 'WORLD' | 'VIEW' | 'PROJECTION' | 'WORLDVIEW' | 'VIEWPROJECTION' | 'WORLDVIEWPROJECTION' | 'WORLDINVERSE' | 'VIEWINVERSE' | 'PROJECTIONINVERSE' | 'WORLDVIEWINVERSE' | 'VIEWPROJECTIONINVERSE' | 'WORLDVIEWPROJECTIONINVERSE'; export type MatrixSemantic = MatrixSemanticNoTranpose | 'WORLDTRANSPOSE' | 'VIEWTRANSPOSE' | 'PROJECTIONTRANSPOSE' | 'WORLDVIEWTRANSPOSE' | 'VIEWPROJECTIONTRANSPOSE' | 'WORLDVIEWPROJECTIONTRANSPOSE' | 'WORLDINVERSETRANSPOSE' | 'VIEWINVERSETRANSPOSE' | 'PROJECTIONINVERSETRANSPOSE' | 'WORLDVIEWINVERSETRANSPOSE' | 'VIEWPROJECTIONINVERSETRANSPOSE' | 'WORLDVIEWPROJECTIONINVERSETRANSPOSE'; export declare function glsl(strings: TemplateStringsArray, ...values: string[]): string; type ShaderUniformLoose = { type: UniformType; value?: unknown; semantic?: AttributeSemantic | UniformSemantic | MatrixSemantic; len?: number | string; array?: boolean; }; type ShaderAttributeLoose = { type: NativeAttributeType; semantic?: AttributeSemantic; }; type ShaderVaringLoose = { type: UniformType; }; export declare function createUniform(type: T, value?: Exclude, semantic?: S): { type: T; value: NativeUniformValueMap[T]; semantic: S | undefined; }; export declare function createSemanticUniform(type: T, semantic: S): { type: T; semantic: S; }; export declare function createArrayUniform(type: T, len: string | number, // Can be a define SKIN_COUNT or literal number value?: NativeUniformArrayValueMap[T]): { type: T; value: NativeUniformArrayValueMap[T] | undefined; len: string | number; array: true; }; export declare function createAttribute(type: T, semantic?: S): { type: T; semantic: S | undefined; }; export declare function createVarying(type: T): { type: T; }; type ShaderFunctionLoose = (functionName?: string) => string; export interface ShaderMixinLoose { defines: Dict; uniforms: Dict; attributes: Dict; varyings: Dict; functions?: ShaderFunctionLoose[]; main?: string | Dict; } export declare const FUNCTION_NAME_PLACEHOLDER = ""; /** * Shader function is only a plain string that can be reused. * It's not magical. So any shader code can be used here. * It can include multiple functions. Can use #ifdef. * Or even uniforms that want to be not configured */ export declare function createShaderFunction(code: string, defaultName?: T): { (functionName?: string): string; displayName: T | undefined; }; export declare function createShaderMixin = {}, TUniforms extends Dict = {}, TAttributes extends Dict = {}, TVaryings extends Dict = {}, TCode extends Dict | string = string>(options: { defines?: TDefines; uniforms?: TUniforms; attributes?: TAttributes; varyings?: TVaryings; /** * Shader funcitons chunk will be assembled before main code. */ functions?: ShaderFunctionLoose[]; main?: TCode; } | string): { defines: TDefines; uniforms: TUniforms; attributes: TAttributes; varyings: TVaryings; functions: ShaderFunctionLoose[]; main: TCode; }; type MergeChunk = UnionToIntersection; declare class StageShader = Dict, TUniforms extends Dict = {}, TAttributes extends Dict = {}, TVaryings extends Dict = {}, TMixins extends ShaderMixinLoose[] = never> { readonly defines: TDefines & MergeChunk; readonly uniforms: TUniforms & MergeChunk; readonly attributes: TAttributes & MergeChunk; readonly varyings: TVaryings & MergeChunk; readonly functions: ShaderFunctionLoose[]; readonly main: string; constructor(options: { name?: string; defines?: TDefines; uniforms?: TUniforms; attributes?: TAttributes; varyings?: TVaryings; includes?: TMixins; main: string; }); } export declare class VertexShader = Dict, TUniforms extends Dict = {}, TAttributes extends Dict = {}, TVaryings extends Dict = {}, TMixins extends ShaderMixinLoose[] = never> extends StageShader { constructor(options: { name?: string; defines?: TDefines; uniforms?: TUniforms; attributes?: TAttributes; varyings?: TVaryings; /** * uniform, defines, attributes, varyings,functions in mixins will be merged automatically. */ includes?: TMixins; main: string; }); } export declare class FragmentShader = Dict, TUniforms extends Dict = {}, TMixins extends ShaderMixinLoose[] = never> extends StageShader { outputs: string[]; constructor(options: { name?: string; defines?: TDefines; uniforms?: TUniforms; /** * uniform, defines, attributes, varyings,functions in mixins will be merged automatically. */ includes?: TMixins; /** * Fragment shader outputs. Default to be ['color'] */ outputs?: string[]; main: string; }); } export type VertexShaderLoose = VertexShader, Dict, Dict, Dict>; export type FragmentShaderLoose = FragmentShader, Dict>; export type PickFragmentTextureUniforms, Dict>['uniforms']> = Pick; export declare class Shader, Dict, Dict, Dict>, F extends FragmentShader = FragmentShader, Dict>> { readonly vertexDefines: Dict; readonly fragmentDefines: Dict; readonly textures: Record; /** * Processed uniform for material */ readonly uniformTpls: V['uniforms'] & F['uniforms']; /** * Processed attributes for geometry */ readonly attributes: Record; readonly semanticsMap: Partial & Record>; readonly matrixSemantics: MatrixSemantic[]; readonly vertex: string; readonly fragment: string; readonly outputs: string[]; private readonly _shaderID; /** * If enable parallel compile. * Only available when renderer#parallelShaderCompile is true. */ parallelCompile?: boolean; version: 3; get shaderID(): string; createUniforms(): V["uniforms"] & F["uniforms"]; constructor(vert: V, frag: F); static uniform: typeof createUniform; static arrayUniform: typeof createArrayUniform; static attribute: typeof createAttribute; static varying: typeof createVarying; static semanticUniform: typeof createSemanticUniform; static Vertex: typeof VertexShader; static Fragment: typeof FragmentShader; } export declare function isTextureUniform(uniform: { type: UniformType; }): boolean; export default Shader;