Skip to content

Commit 0ac72f2

Browse files
committed
Use specified side unless object is transmissive
1 parent f33fbde commit 0ac72f2

File tree

4 files changed

+28
-53
lines changed

4 files changed

+28
-53
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -722,14 +722,6 @@ Three.js materials support only a single set of UV transforms in a certain fallb
722722

723723
See fallback order documentation [here](https://threejs.org/docs/#api/en/textures/Texture.offset).
724724

725-
### .setSide
726-
727-
```js
728-
setSide( index : Number, side : FrontSide | BackSide | DoubleSide ) : void
729-
```
730-
731-
Sets the side to render for the given material.
732-
733725
### .setMatte
734726

735727
```js

example/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</div>
6161
</div>
6262
<script type="module">
63-
import { MeshPhysicalMaterial, Color } from 'three';
63+
import { MeshPhysicalMaterial, Color, DoubleSide } from 'three';
6464

6565
window.MODEL_LIST = {
6666
'M2020 Rover': {
@@ -300,6 +300,7 @@
300300
roughness: 0.25,
301301
transmission: 1,
302302
ior: 1.5,
303+
side: DoubleSide,
303304
} ) ;
304305

305306
model.traverse( c => {

example/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ async function init() {
166166
transparent: true,
167167
color: 0x080808,
168168
roughness: 0.1,
169-
metalness: 0.0
169+
metalness: 0.0,
170+
side: DoubleSide,
170171
} )
171172
);
172173
floorPlane.scale.setScalar( 3 );

src/uniforms/MaterialsTexture.js

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { DataTexture, RGBAFormat, ClampToEdgeWrapping, FloatType, FrontSide, Bac
33
const MATERIAL_PIXELS = 45;
44
const MATERIAL_STRIDE = MATERIAL_PIXELS * 4;
55

6-
const SIDE_OFFSET = 13 * 4 + 3; // s12.a
76
const MATTE_OFFSET = 14 * 4 + 0; // s14.r
87
const SHADOW_OFFSET = 14 * 4 + 1; // s14.g
98

@@ -39,45 +38,6 @@ export class MaterialsTexture extends DataTexture {
3938

4039
}
4140

42-
setSide( materialIndex, side ) {
43-
44-
const array = this.image.data;
45-
const index = materialIndex * MATERIAL_STRIDE + SIDE_OFFSET;
46-
switch ( side ) {
47-
48-
case FrontSide:
49-
array[ index ] = 1;
50-
break;
51-
case BackSide:
52-
array[ index ] = - 1;
53-
break;
54-
case DoubleSide:
55-
array[ index ] = 0;
56-
break;
57-
58-
}
59-
60-
}
61-
62-
getSide( materialIndex ) {
63-
64-
const array = this.image.data;
65-
const index = materialIndex * MATERIAL_STRIDE + SIDE_OFFSET;
66-
switch ( array[ index ] ) {
67-
68-
case 0:
69-
return DoubleSide;
70-
case 1:
71-
return FrontSide;
72-
case - 1:
73-
return BackSide;
74-
75-
}
76-
77-
return 0;
78-
79-
}
80-
8141
setMatte( materialIndex, matte ) {
8242

8343
const array = this.image.data;
@@ -336,8 +296,9 @@ export class MaterialsTexture extends DataTexture {
336296
floatArray[ index ++ ] = getField( m, 'specularIntensity', 1.0 );
337297
floatArray[ index ++ ] = getTexture( m, 'specularIntensityMap' );
338298

339-
// thickness
340-
floatArray[ index ++ ] = getField( m, 'thickness', 0.0 ) === 0.0 && getField( m, 'attenuationDistance', Infinity ) === Infinity;
299+
// isThinFilm
300+
const isThinFilm = getField( m, 'thickness', 0.0 ) === 0.0 && getField( m, 'attenuationDistance', Infinity ) === Infinity;
301+
floatArray[ index ++ ] = Number( isThinFilm );
341302
index ++;
342303

343304
// sample 12
@@ -364,7 +325,27 @@ export class MaterialsTexture extends DataTexture {
364325
// side & matte
365326
floatArray[ index ++ ] = m.opacity;
366327
floatArray[ index ++ ] = m.alphaTest;
367-
index ++; // side
328+
if ( ! isThinFilm && m.transmission > 0.0 ) {
329+
330+
floatArray[ index ++ ] = 0;
331+
332+
} else {
333+
334+
switch ( m.side ) {
335+
336+
case FrontSide:
337+
floatArray[ index ++ ] = 1;
338+
break;
339+
case BackSide:
340+
floatArray[ index ++ ] = - 1;
341+
break;
342+
case DoubleSide:
343+
floatArray[ index ++ ] = 0;
344+
break;
345+
346+
}
347+
348+
}
368349

369350
// sample 14
370351
index ++; // matte

0 commit comments

Comments
 (0)