22 * @author sunag / http://www.sunag.com.br/
33 */
44
5+ import {
6+ BackSide
7+ } from '../../../../build/three.module.js' ;
8+
59import { TempNode } from '../core/TempNode.js' ;
610import { Vector2Node } from '../inputs/Vector2Node.js' ;
711import { FunctionNode } from '../core/FunctionNode.js' ;
@@ -25,7 +29,7 @@ NormalMapNode.Nodes = ( function () {
2529 // Per-Pixel Tangent Space Normal Mapping
2630 // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
2731
28- `vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 map, vec2 vUv, vec2 normalScale ) {
32+ `vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 map, vec2 vUv, vec2 normalScale ) {
2933
3034 // Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
3135
@@ -47,14 +51,8 @@ NormalMapNode.Nodes = ( function () {
4751 #ifdef DOUBLE_SIDED
4852
4953 // Workaround for Adreno GPUs gl_FrontFacing bug. See #15850 and #10331
50- // http://hacksoflife.blogspot.com/2009/11/per-pixel-tangent-space-normal-mapping.html?showComment=1522254677437#c5087545147696715943
51- vec3 NfromST = cross( S, T );
52- if( dot( NfromST, N ) > 0.0 ) {
53-
54- S *= -1.0;
55- T *= -1.0;
5654
57- }
55+ if ( dot( cross( S, T ), N ) < 0.0 ) mapN.xy *= - 1.0;
5856
5957 #else
6058
@@ -87,11 +85,19 @@ NormalMapNode.prototype.generate = function ( builder, output ) {
8785 this . position = this . position || new PositionNode ( PositionNode . VIEW ) ;
8886 this . uv = this . uv || new UVNode ( ) ;
8987
88+ var scale = this . scale . build ( builder , 'v2' ) ;
89+
90+ if ( builder . material . side === BackSide ) {
91+
92+ scale = '-' + scale ;
93+
94+ }
95+
9096 return builder . format ( perturbNormal2Arb + '( -' + this . position . build ( builder , 'v3' ) + ', ' +
9197 this . normal . build ( builder , 'v3' ) + ', ' +
9298 this . value . build ( builder , 'v3' ) + ', ' +
9399 this . uv . build ( builder , 'v2' ) + ', ' +
94- this . scale . build ( builder , 'v2' ) + ' )' , this . getType ( builder ) , output ) ;
100+ scale + ' )' , this . getType ( builder ) , output ) ;
95101
96102 } else {
97103
0 commit comments