UNPKG

3.56 kBTypeScriptView Raw
1import { GLSLVersion } from "../constants.js";
2import { JSONMeta } from "../core/Object3D.js";
3import { UniformsGroup } from "../core/UniformsGroup.js";
4import { Matrix3, Matrix3Tuple } from "../math/Matrix3.js";
5import { Matrix4, Matrix4Tuple } from "../math/Matrix4.js";
6import { Vector2Tuple } from "../math/Vector2.js";
7import { Vector3Tuple } from "../math/Vector3.js";
8import { Vector4Tuple } from "../math/Vector4.js";
9import { IUniform } from "../renderers/shaders/UniformsLib.js";
10import { Material, MaterialJSON, MaterialParameters } from "./Material.js";
11
12export interface ShaderMaterialParameters extends MaterialParameters {
13 uniforms?: { [uniform: string]: IUniform } | undefined;
14 uniformsGroups?: UniformsGroup[] | undefined;
15 vertexShader?: string | undefined;
16 fragmentShader?: string | undefined;
17 linewidth?: number | undefined;
18 wireframe?: boolean | undefined;
19 wireframeLinewidth?: number | undefined;
20 lights?: boolean | undefined;
21 clipping?: boolean | undefined;
22 fog?: boolean | undefined;
23 extensions?:
24 | {
25 clipCullDistance?: boolean | undefined;
26 multiDraw?: boolean | undefined;
27 }
28 | undefined;
29 glslVersion?: GLSLVersion | undefined;
30}
31
32export type ShaderMaterialUniformJSON = {
33 type: "t";
34 value: string;
35} | {
36 type: "c";
37 value: number;
38} | {
39 type: "v2";
40 value: Vector2Tuple;
41} | {
42 type: "v3";
43 value: Vector3Tuple;
44} | {
45 type: "v4";
46 value: Vector4Tuple;
47} | {
48 type: "m3";
49 value: Matrix3Tuple;
50} | {
51 type: "m4";
52 value: Matrix4Tuple;
53} | {
54 value: unknown;
55};
56
57export interface ShaderMaterialJSON extends MaterialJSON {
58 glslVersion: number | null;
59 uniforms: Record<string, ShaderMaterialUniformJSON>;
60
61 defines?: Record<string, unknown>;
62
63 vertexShader: string;
64 ragmentShader: string;
65
66 lights: boolean;
67 clipping: boolean;
68
69 extensions?: Record<string, boolean>;
70}
71
72export class ShaderMaterial extends Material {
73 constructor(parameters?: ShaderMaterialParameters);
74
75 /**
76 * Read-only flag to check if a given object is of type {@link ShaderMaterial}.
77 * @remarks This is a _constant_ value
78 * @defaultValue `true`
79 */
80 readonly isShaderMaterial: true;
81
82 /**
83 * @default {}
84 */
85 defines: { [key: string]: any };
86
87 /**
88 * @default {}
89 */
90 uniforms: { [uniform: string]: IUniform };
91
92 uniformsGroups: UniformsGroup[];
93
94 vertexShader: string;
95
96 fragmentShader: string;
97
98 /**
99 * @default 1
100 */
101 linewidth: number;
102
103 /**
104 * @default false
105 */
106 wireframe: boolean;
107
108 /**
109 * @default 1
110 */
111 wireframeLinewidth: number;
112
113 /**
114 * @default false
115 */
116 fog: boolean;
117
118 /**
119 * @default false
120 */
121 lights: boolean;
122
123 /**
124 * @default false
125 */
126 clipping: boolean;
127
128 /**
129 * @default {
130 * clipCullDistance: false,
131 * multiDraw: false
132 * }
133 */
134 extensions: {
135 clipCullDistance: boolean;
136 multiDraw: boolean;
137 };
138
139 /**
140 * @default { 'color': [ 1, 1, 1 ], 'uv': [ 0, 0 ], 'uv1': [ 0, 0 ] }
141 */
142 defaultAttributeValues: any;
143
144 /**
145 * @default undefined
146 */
147 index0AttributeName: string | undefined;
148
149 /**
150 * @default false
151 */
152 uniformsNeedUpdate: boolean;
153
154 /**
155 * @default null
156 */
157 glslVersion: GLSLVersion | null;
158
159 setValues(parameters: ShaderMaterialParameters): void;
160
161 toJSON(meta?: JSONMeta): ShaderMaterialJSON;
162}