From 5723b91b32a047542a9f2f17b9492cf9cf25721e Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Sun, 4 Oct 2020 09:36:10 +0200 Subject: [PATCH] Fix inverted bug --- .../uniform-array-autoscaling-program.ts | 17 +++++++++-------- .../rendering/shaders/distance-fs-100.glsl | 6 +----- src/graphics/rendering/shaders/distance-fs.glsl | 6 +----- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts b/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts index e5063a9..b15ea0c 100644 --- a/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts +++ b/src/graphics/graphics-library/program/uniform-array-autoscaling-program.ts @@ -24,8 +24,8 @@ export class UniformArrayAutoScalingProgram implements IProgram { public async initialize( shaderSources: [string, string], descriptors: Array, - substitutions: { [name: string]: any }, - compiler: ParallelCompiler + compiler: ParallelCompiler, + substitutions: { [name: string]: any } = {} ): Promise { this.descriptors = descriptors; @@ -118,7 +118,7 @@ export class UniformArrayAutoScalingProgram implements IProgram { }; const program = new FragmentShaderOnlyProgram(this.gl); - await program.initialize(shaderSources, processedSubstitutions, compiler); + await program.initialize(shaderSources, compiler, processedSubstitutions); this.programs.push({ program, @@ -161,10 +161,6 @@ export class UniformArrayAutoScalingProgram implements IProgram { } return ` - #ifndef NOT_EMPTY - #define NOT_EMPTY - #endif - objectMinDistance = ${ descriptors[i].sdf!.distanceFunctionName }(position, objectColor); @@ -179,7 +175,12 @@ export class UniformArrayAutoScalingProgram implements IProgram { } ); - minDistance = min(minDistance, objectMinDistance); + ${ + descriptors[i].sdf?.isInverted + ? 'minDistance = max(minDistance, objectMinDistance);' + : 'minDistance = min(minDistance, objectMinDistance);' + } + `; }) .join('\n'); diff --git a/src/graphics/rendering/shaders/distance-fs-100.glsl b/src/graphics/rendering/shaders/distance-fs-100.glsl index eba9f1e..0a6a1b5 100644 --- a/src/graphics/rendering/shaders/distance-fs-100.glsl +++ b/src/graphics/rendering/shaders/distance-fs-100.glsl @@ -11,16 +11,12 @@ varying vec2 position; {declarations} void main() { - float minDistance = abs(maxMinDistance); + float minDistance = maxMinDistance; float color = 0.0; float objectMinDistance, objectColor; {functionCalls} - #ifndef NOT_EMPTY - minDistance = maxMinDistance; - #endif - gl_FragColor = vec4(minDistance * 8.0, color, 0.0, 1.0); } diff --git a/src/graphics/rendering/shaders/distance-fs.glsl b/src/graphics/rendering/shaders/distance-fs.glsl index 14e122e..e16eef4 100644 --- a/src/graphics/rendering/shaders/distance-fs.glsl +++ b/src/graphics/rendering/shaders/distance-fs.glsl @@ -13,16 +13,12 @@ in vec2 position; out vec2 fragmentColor; void main() { - float minDistance = abs(maxMinDistance); + float minDistance = maxMinDistance; float color = 0.0; float objectMinDistance, objectColor; {functionCalls} - #ifndef NOT_EMPTY - minDistance = maxMinDistance; - #endif - fragmentColor = vec2(minDistance, color); }