Browse Source

Fix linear/gamma space not taken into account

Popov72 4 years ago
parent
commit
e5dd6790b8
1 changed files with 15 additions and 11 deletions
  1. 15 11
      src/Materials/Node/Blocks/Dual/textureBlock.ts

+ 15 - 11
src/Materials/Node/Blocks/Dual/textureBlock.ts

@@ -320,6 +320,18 @@ export class TextureBlock extends NodeMaterialBlock {
         state.compilationString += `#endif\r\n`;
     }
 
+    private _generateConversionCode(state: NodeMaterialBuildState, output: NodeMaterialConnectionPoint, swizzle: string): void {
+        if (swizzle !== 'a') { // no conversion if the output is "a" (alpha)
+            state.compilationString += `#ifdef ${this._linearDefineName}\r\n`;
+            state.compilationString += `${output.associatedVariableName} = toGammaSpace(${output.associatedVariableName});\r\n`;
+            state.compilationString += `#endif\r\n`;
+
+            state.compilationString += `#ifdef ${this._gammaDefineName}\r\n`;
+            state.compilationString += `${output.associatedVariableName} = toLinearSpace(${output.associatedVariableName});\r\n`;
+            state.compilationString += `#endif\r\n`;
+        }
+    }
+
     private _writeOutput(state: NodeMaterialBuildState, output: NodeMaterialConnectionPoint, swizzle: string, vertexMode = false) {
         if (vertexMode) {
             if (state.target === NodeMaterialBlockTargets.Fragment) {
@@ -327,28 +339,20 @@ export class TextureBlock extends NodeMaterialBlock {
             }
 
             state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\r\n`;
-
+            this._generateConversionCode(state, output, swizzle);
             return;
         }
 
         if (this.uv.ownerBlock.target === NodeMaterialBlockTargets.Fragment) {
             state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle};\r\n`;
+            this._generateConversionCode(state, output, swizzle);
             return;
         }
 
         const complement = ` * ${this._textureInfoName}`;
 
         state.compilationString += `${this._declareOutput(output, state)} = ${this._tempTextureRead}.${swizzle}${complement};\r\n`;
-
-        if (swizzle !== 'a') { // no conversion if the output is "a" (alpha)
-            state.compilationString += `#ifdef ${this._linearDefineName}\r\n`;
-            state.compilationString += `${output.associatedVariableName} = toGammaSpace(${output.associatedVariableName});\r\n`;
-            state.compilationString += `#endif\r\n`;
-
-            state.compilationString += `#ifdef ${this._gammaDefineName}\r\n`;
-            state.compilationString += `${output.associatedVariableName} = toLinearSpace(${output.associatedVariableName});\r\n`;
-            state.compilationString += `#endif\r\n`;
-        }
+        this._generateConversionCode(state, output, swizzle);
     }
 
     protected _buildBlock(state: NodeMaterialBuildState) {