Skip to content
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

Update Shader and UniformsUtils #719

Merged
merged 17 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
5 changes: 2 additions & 3 deletions types/three/src/renderers/shaders/ShaderLib.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { WebGLProgramParameters } from '../webgl/WebGLProgramParameters.js';
import { IUniform } from './UniformsLib.js';

export interface Shader {
export interface Shader extends WebGLProgramParameters {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I rename Shader to WebGLProgramParametersWithUniforms? I think Shader works too as a parameter type.

Copy link
Contributor

@Methuselah96 Methuselah96 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually thinking we'd keep Shader as-is, since it's really just intended to describe the type of shaders in ShaderLib. Maybe it should be renamed to ShaderLibShader to make that more clear? I was thinking we'd export a WebGLProgramParametersWithUniforms interface from WebGLRenderer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've exported WebGLProgramParametersWithUniforms from WebGLPrograms since it's used there as a param type for acquireProgram. Is there a specific reason why it should be in WebGLRenderer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that should be fine, thanks.

uniforms: { [uniform: string]: IUniform };
vertexShader: string;
fragmentShader: string;
}

export let ShaderLib: {
Expand Down
5 changes: 3 additions & 2 deletions types/three/src/renderers/shaders/UniformsUtils.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { UniformsGroup } from '../../core/UniformsGroup.js';
import { IUniform } from './UniformsLib.js';

export function cloneUniforms(uniforms_src: any): any;
export function mergeUniforms(uniforms: any): any;
export function cloneUniforms<T extends { [uniform: string]: IUniform }>(uniformsSrc: T): T;
export function mergeUniforms(uniforms: Array<{ [uniform: string]: IUniform }>): { [uniform: string]: IUniform };

export function cloneUniformsGroups(src: UniformsGroup[]): UniformsGroup[];

Expand Down
76 changes: 39 additions & 37 deletions types/three/src/renderers/webgl/WebGLLights.d.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import { WebGLExtensions } from './WebGLExtensions.js';
import { WebGLCapabilities } from './WebGLCapabilities.js';

export class WebGLLights {
constructor(extensions: WebGLExtensions, capabilities: WebGLCapabilities);
export interface WebGLLightsState {
version: number;

hash: {
directionalLength: number;
pointLength: number;
spotLength: number;
rectAreaLength: number;
hemiLength: number;

numDirectionalShadows: number;
numPointShadows: number;
numSpotShadows: number;
numSpotMaps: number;

state: {
version: number;

hash: {
directionalLength: number;
pointLength: number;
spotLength: number;
rectAreaLength: number;
hemiLength: number;

numDirectionalShadows: number;
numPointShadows: number;
numSpotShadows: number;
numSpotMaps: number;

numLightProbes: number;
};

ambient: number[];
probe: any[];
directional: any[];
directionalShadow: any[];
directionalShadowMap: any[];
directionalShadowMatrix: any[];
spot: any[];
spotShadow: any[];
spotShadowMap: any[];
spotShadowMatrix: any[];
rectArea: any[];
point: any[];
pointShadow: any[];
pointShadowMap: any[];
pointShadowMatrix: any[];
hemi: any[];
numSpotLightShadowsWithMaps: number;
numLightProbes: number;
};

ambient: number[];
probe: any[];
directional: any[];
directionalShadow: any[];
directionalShadowMap: any[];
directionalShadowMatrix: any[];
spot: any[];
spotShadow: any[];
spotShadowMap: any[];
spotShadowMatrix: any[];
rectArea: any[];
point: any[];
pointShadow: any[];
pointShadowMap: any[];
pointShadowMatrix: any[];
hemi: any[];
numSpotLightShadowsWithMaps: number;
numLightProbes: number;
}

export class WebGLLights {
constructor(extensions: WebGLExtensions, capabilities: WebGLCapabilities);

state: WebGLLightsState;

get(light: any): any;
setup(lights: any): void;
setupView(lights: any, camera: any): void;
Expand Down
199 changes: 199 additions & 0 deletions types/three/src/renderers/webgl/WebGLProgramParameters.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import {
ColorSpace,
Combine,
DepthPackingStrategies,
GLSLVersion,
ShadowMapType,
ToneMapping,
} from '../../constants.js';

export interface WebGLProgramParameters {
vanruesc marked this conversation as resolved.
Show resolved Hide resolved
isWebGL2: boolean;

shaderID: string;
shaderType: string;
shaderName: string;

vertexShader: string;
fragmentShader: string;
defines?: { [define: string]: string | number | boolean };
vanruesc marked this conversation as resolved.
Show resolved Hide resolved

customVertexShaderID?: string;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved
customFragmentShaderID?: string;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved

isRawShaderMaterial: boolean;
glslVersion?: GLSLVersion;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved

precision: 'lowp' | 'mediump' | 'highp';

batching: boolean;
instancing: boolean;
instancingColor: boolean;

supportsVertexTextures: boolean;
outputColorSpace: ColorSpace;

map: boolean;
matcap: boolean;
envMap: boolean;
envMapMode: boolean;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved
envMapCubeUVHeight: number | null;
aoMap: boolean;
lightMap: boolean;
bumpMap: boolean;
normalMap: boolean;
displacementMap: boolean;
emissiveMap: boolean;

normalMapObjectSpace: boolean;
normalMapTangentSpace: boolean;

metalnessMap: boolean;
roughnessMap: boolean;

anisotropy: boolean;
anisotropyMap: boolean;

clearcoat: boolean;
clearcoatMap: boolean;
clearcoatNormalMap: boolean;
clearcoatRoughnessMap: boolean;

iridescence: boolean;
iridescenceMap: boolean;
iridescenceThicknessMap: boolean;

sheen: boolean;
sheenColorMap: boolean;
sheenRoughnessMap: boolean;

specularMap: boolean;
specularColorMap: boolean;
specularIntensityMap: boolean;

transmission: boolean;
transmissionMap: boolean;
thicknessMap: boolean;

gradientMap: boolean;

opaque: boolean;

alphaMap: boolean;
alphaTest: boolean;
alphaHash: boolean;

combine: Combine;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved

//

mapUv: boolean;
aoMapUv: boolean;
lightMapUv: boolean;
bumpMapUv: boolean;
normalMapUv: boolean;
displacementMapUv: boolean;
emissiveMapUv: boolean;

metalnessMapUv: boolean;
roughnessMapUv: boolean;

anisotropyMapUv: boolean;

clearcoatMapUv: boolean;
clearcoatNormalMapUv: boolean;
clearcoatRoughnessMapUv: boolean;

iridescenceMapUv: boolean;
iridescenceThicknessMapUv: boolean;

sheenColorMapUv: boolean;
sheenRoughnessMapUv: boolean;

specularMapUv: boolean;
specularColorMapUv: boolean;
specularIntensityMapUv: boolean;

transmissionMapUv: boolean;
thicknessMapUv: boolean;

alphaMapUv: boolean;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved

//

vertexTangents: boolean;
vertexColors: boolean;
vertexAlphas: boolean;
vertexUv1s: boolean;
vertexUv2s: boolean;
vertexUv3s: boolean;

pointsUvs: boolean;

fog: boolean;
useFog: boolean;
fogExp2: boolean | null; // null is possible because of a bug: ( fog && fog.isFogExp2 )

flatShading: boolean;

sizeAttenuation: boolean;
logarithmicDepthBuffer: boolean;

skinning: boolean;

morphTargets: boolean;
morphNormals: boolean;
morphColors: boolean;
morphTargetsCount: number;
morphTextureStride: number;

numDirLights: number;
numPointLights: number;
numSpotLights: number;
numSpotLightMaps: number;
numRectAreaLights: number;
numHemiLights: number;

numDirLightShadows: number;
numPointLightShadows: number;
numSpotLightShadows: number;
numSpotLightShadowsWithMaps: number;

numLightProbes: number;

numClippingPlanes: number;
numClipIntersection: number;

dithering: boolean;

shadowMapEnabled: boolean;
shadowMapType: ShadowMapType;

toneMapping: ToneMapping;
useLegacyLights: boolean;

decodeVideoTexture: boolean;

premultipliedAlpha: boolean;

doubleSided: boolean;
flipSided: boolean;

useDepthPacking: boolean;
depthPacking: DepthPackingStrategies;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved

index0AttributeName: string;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved

extensionDerivatives: boolean;
extensionFragDepth: boolean;
extensionDrawBuffers: boolean;
extensionShaderTextureLOD: boolean;
extensionClipCullDistance: boolean;

rendererExtensionFragDepth: boolean;
rendererExtensionDrawBuffers: boolean;
rendererExtensionShaderTextureLod: boolean;
rendererExtensionParallelShaderCompile: boolean;

customProgramCacheKey: string;
}
30 changes: 21 additions & 9 deletions types/three/src/renderers/webgl/WebGLPrograms.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Material } from '../../materials/Material.js';
import { Object3D } from '../../core/Object3D.js';
import { Light } from '../../lights/Light.js';
import { Scene } from '../../scenes/Scene.js';
import { IUniform } from '../shaders/UniformsLib.js';
import { WebGLRenderer } from '../WebGLRenderer.js';
import { WebGLProgram } from './WebGLProgram.js';
import { WebGLBindingStates } from './WebGLBindingStates.js';
import { WebGLCapabilities } from './WebGLCapabilities.js';
import { WebGLClipping } from './WebGLClipping.js';
import { WebGLCubeMaps } from './WebGLCubeMaps.js';
import { WebGLExtensions } from './WebGLExtensions.js';
import { WebGLClipping } from './WebGLClipping.js';
import { WebGLBindingStates } from './WebGLBindingStates.js';
import { Material } from '../../materials/Material.js';
import { Scene } from '../../scenes/Scene.js';
import { WebGLLightsState } from './WebGLLights.js';
import { WebGLProgram } from './WebGLProgram.js';
import { WebGLProgramParameters } from './WebGLProgramParameters.js';

export class WebGLPrograms {
constructor(
Expand All @@ -20,9 +25,16 @@ export class WebGLPrograms {

programs: WebGLProgram[];

getParameters(material: Material, lights: any, shadows: object[], scene: Scene, object: any): any;
getProgramCacheKey(parameters: any): string;
getUniforms(material: Material): object;
acquireProgram(parameters: any, cacheKey: string): WebGLProgram;
getParameters(
material: Material,
lights: WebGLLightsState,
shadows: Light[],
scene: Scene,
object: Object3D,
): WebGLProgramParameters;
vanruesc marked this conversation as resolved.
Show resolved Hide resolved

getProgramCacheKey(parameters: WebGLProgramParameters): string;
getUniforms(material: Material): { [uniform: string]: IUniform };
acquireProgram(parameters: WebGLProgramParameters, cacheKey: string): WebGLProgram;
releaseProgram(program: WebGLProgram): void;
}
Loading