1
- import { MathUtil , Vector2 , Vector3 , Vector4 } from "@galacean/engine-math" ;
1
+ import { MathUtil , Vector2 , Vector3 , Vector4 , Color } from "@galacean/engine-math" ;
2
2
import { Engine } from "../Engine" ;
3
3
import { ShaderProperty } from "../shader" ;
4
4
import { Shader } from "../shader/Shader" ;
@@ -25,6 +25,12 @@ export class PBRMaterial extends PBRBaseMaterial {
25
25
private static _iridescenceTextureProp = ShaderProperty . getByName ( "material_IridescenceTexture" ) ;
26
26
private _iridescenceRange = new Vector2 ( 100 , 400 ) ;
27
27
28
+ private _sheenEnabled = false ;
29
+ private static _sheenColorProp = ShaderProperty . getByName ( "material_SheenColor" ) ;
30
+ private static _sheenRoughnessProp = ShaderProperty . getByName ( "material_SheenRoughness" ) ;
31
+ private static _sheenTextureProp = ShaderProperty . getByName ( "material_SheenTexture" ) ;
32
+ private static _sheenRoughnessTextureProp = ShaderProperty . getByName ( "material_SheenRoughnessTexture" ) ;
33
+
28
34
/**
29
35
* Index Of Refraction.
30
36
* @defaultValue `1.5`
@@ -190,7 +196,7 @@ export class PBRMaterial extends PBRBaseMaterial {
190
196
191
197
/**
192
198
* The range of iridescence thickness, x is minimum, y is maximum.
193
- * @defaultValue `[100, 400]`.
199
+ * @defaultValue `[100, 400]`
194
200
*/
195
201
get iridescenceThicknessRange ( ) : Vector2 {
196
202
return this . _iridescenceRange ;
@@ -222,6 +228,67 @@ export class PBRMaterial extends PBRBaseMaterial {
222
228
}
223
229
}
224
230
231
+ /**
232
+ * Sheen color.
233
+ * @defaultValue `[0,0,0]`
234
+ */
235
+ get sheenColor ( ) : Color {
236
+ return this . shaderData . getColor ( PBRMaterial . _sheenColorProp ) ;
237
+ }
238
+
239
+ set sheenColor ( value : Color ) {
240
+ const sheenColor = this . shaderData . getColor ( PBRMaterial . _sheenColorProp ) ;
241
+ if ( value !== sheenColor ) {
242
+ sheenColor . copyFrom ( value ) ;
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Sheen roughness, from 0.0 to 1.0.
248
+ * @defaultValue `0.0`
249
+ */
250
+ get sheenRoughness ( ) : number {
251
+ return this . shaderData . getFloat ( PBRMaterial . _sheenRoughnessProp ) ;
252
+ }
253
+
254
+ set sheenRoughness ( value : number ) {
255
+ value = Math . max ( 0 , Math . min ( 1 , value ) ) ;
256
+ this . shaderData . setFloat ( PBRMaterial . _sheenRoughnessProp , value ) ;
257
+ }
258
+
259
+ /**
260
+ * Sheen color texture, multiply ‘sheenColor’.
261
+ */
262
+ get sheenColorTexture ( ) : Texture2D {
263
+ return < Texture2D > this . shaderData . getTexture ( PBRMaterial . _sheenTextureProp ) ;
264
+ }
265
+
266
+ set sheenColorTexture ( value : Texture2D ) {
267
+ this . shaderData . setTexture ( PBRMaterial . _sheenTextureProp , value ) ;
268
+ if ( value ) {
269
+ this . shaderData . enableMacro ( "MATERIAL_HAS_SHEEN_TEXTURE" ) ;
270
+ } else {
271
+ this . shaderData . disableMacro ( "MATERIAL_HAS_SHEEN_TEXTURE" ) ;
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Sheen roughness texture.
277
+ * @remarks Use alpha channel, and multiply 'sheenRoughness'.
278
+ */
279
+ get sheenRoughnessTexture ( ) : Texture2D {
280
+ return < Texture2D > this . shaderData . getTexture ( PBRMaterial . _sheenRoughnessTextureProp ) ;
281
+ }
282
+
283
+ set sheenRoughnessTexture ( value : Texture2D ) {
284
+ this . shaderData . setTexture ( PBRMaterial . _sheenRoughnessTextureProp , value ) ;
285
+ if ( value ) {
286
+ this . shaderData . enableMacro ( "MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE" ) ;
287
+ } else {
288
+ this . shaderData . disableMacro ( "MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE" ) ;
289
+ }
290
+ }
291
+
225
292
/**
226
293
* Create a pbr metallic-roughness workflow material instance.
227
294
* @param engine - Engine to which the material belongs
@@ -235,8 +302,22 @@ export class PBRMaterial extends PBRBaseMaterial {
235
302
shaderData . setFloat ( PBRMaterial . _iorProp , 1.5 ) ;
236
303
shaderData . setVector3 ( PBRMaterial . _anisotropyInfoProp , new Vector3 ( 1 , 0 , 0 ) ) ;
237
304
shaderData . setVector4 ( PBRMaterial . _iridescenceInfoProp , new Vector4 ( 0 , 1.3 , 100 , 400 ) ) ;
305
+ const sheenColor = new Color ( 0 , 0 , 0 ) ;
306
+ shaderData . setColor ( PBRMaterial . _sheenColorProp , sheenColor ) ;
238
307
// @ts -ignore
239
308
this . _iridescenceRange . _onValueChanged = this . _onIridescenceRangeChanged . bind ( this ) ;
309
+ // @ts -ignore
310
+ sheenColor . _onValueChanged = ( ) => {
311
+ const enableSheen = sheenColor . r + sheenColor . g + sheenColor . b > 0 ;
312
+ if ( enableSheen !== this . _sheenEnabled ) {
313
+ this . _sheenEnabled = enableSheen ;
314
+ if ( enableSheen ) {
315
+ this . shaderData . enableMacro ( "MATERIAL_ENABLE_SHEEN" ) ;
316
+ } else {
317
+ this . shaderData . disableMacro ( "MATERIAL_ENABLE_SHEEN" ) ;
318
+ }
319
+ }
320
+ } ;
240
321
}
241
322
242
323
private _onIridescenceRangeChanged ( ) : void {
0 commit comments