From 7c29c3a9444aa84945bba3149122b9b915ac6681 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 28 Nov 2020 17:13:18 -0500 Subject: [PATCH 1/4] Given that `lineCompositeAmplitude` is not normalised, ups threshold. --- Outputs/OpenGL/ScanTargetGLSLFragments.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp index d83f6814a..4bc4a50f5 100644 --- a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp +++ b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp @@ -341,7 +341,7 @@ std::unique_ptr ScanTarget::conversion_shader() const { vertex_shader += "compositeAngle = (mix(startCompositeAngle, endCompositeAngle, lateral) / 32.0) * 3.141592654;" "compositeAmplitude = lineCompositeAmplitude / 255.0;" - "oneOverCompositeAmplitude = mix(0.0, 255.0 / lineCompositeAmplitude, step(0.01, lineCompositeAmplitude));"; + "oneOverCompositeAmplitude = mix(0.0, 255.0 / lineCompositeAmplitude, step(0.95, lineCompositeAmplitude));"; } vertex_shader += From 33dec3c220180334bbb6eea45ffeecac4cf4c126 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 28 Nov 2020 17:13:18 -0500 Subject: [PATCH 2/4] Given that `lineCompositeAmplitude` is not normalised, ups threshold. --- Outputs/OpenGL/ScanTargetGLSLFragments.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp index d83f6814a..64f5b6a22 100644 --- a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp +++ b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp @@ -341,7 +341,7 @@ std::unique_ptr ScanTarget::conversion_shader() const { vertex_shader += "compositeAngle = (mix(startCompositeAngle, endCompositeAngle, lateral) / 32.0) * 3.141592654;" "compositeAmplitude = lineCompositeAmplitude / 255.0;" - "oneOverCompositeAmplitude = mix(0.0, 255.0 / lineCompositeAmplitude, step(0.01, lineCompositeAmplitude));"; + "oneOverCompositeAmplitude = mix(0.0, 255.0 / lineCompositeAmplitude, step(0.95, lineCompositeAmplitude));"; } vertex_shader += @@ -622,7 +622,7 @@ std::unique_ptr ScanTarget::qam_separation_shader() const { "compositeAngle = compositeAngle * 2.0 * 3.141592654;" "compositeAmplitude = lineCompositeAmplitude / 255.0;" - "oneOverCompositeAmplitude = mix(0.0, 255.0 / lineCompositeAmplitude, step(0.01, lineCompositeAmplitude));"; + "oneOverCompositeAmplitude = mix(0.0, 255.0 / lineCompositeAmplitude, step(0.95, lineCompositeAmplitude));"; if(is_svideo) { vertex_shader += From 1b3836eb1ca3d23793fe83bf1343b9a37c2ea9e7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 28 Nov 2020 19:47:04 -0500 Subject: [PATCH 3/4] Adds an overt branch for mono/colour composite selection. --- Outputs/OpenGL/ScanTargetGLSLFragments.cpp | 60 +++++++++++----------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp index 64f5b6a22..39e57218e 100644 --- a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp +++ b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp @@ -379,40 +379,42 @@ std::unique_ptr ScanTarget::conversion_shader() const { switch(modals.display_type) { case DisplayType::CompositeColour: - fragment_shader += - "vec4 angles = compositeAngle + compositeAngleOffsets;" + fragment_shader += R"x( + vec4 angles = compositeAngle + compositeAngleOffsets; // Sample four times over, at proper angle offsets. - "vec4 samples = vec4(" - "composite_sample(textureCoordinates[0], angles.x)," - "composite_sample(textureCoordinates[1], angles.y)," - "composite_sample(textureCoordinates[2], angles.z)," - "composite_sample(textureCoordinates[3], angles.w)" - ");" + vec4 samples = vec4( + composite_sample(textureCoordinates[0], angles.x), + composite_sample(textureCoordinates[1], angles.y), + composite_sample(textureCoordinates[2], angles.z), + composite_sample(textureCoordinates[3], angles.w) + ); - // Compute a luminance for use if there's no colour information, now, before - // modifying samples. - "float mono_luminance = dot(samples, vec4(0.15, 0.35, 0.35, 0.15));" + // The outer structure of the OpenGL scan target means in practice that + // oneOverCompositeAmplitude will be the same value across a piece of + // geometry. I am therefore optimistic that this conditional will not + // cause a divergence in fragment execution. + if(oneOverCompositeAmplitude < 0.01) { + // Compute only a luminance for use if there's no colour information. + fragColour3 = vec3(dot(samples, vec4(0.15, 0.35, 0.35, 0.15))); + } else { + // Take the average to calculate luminance, then subtract that from all four samples to + // give chrominance. + float luminance = dot(samples, vec4(0.25)); - // Take the average to calculate luminance, then subtract that from all four samples to - // give chrominance. - "float luminance = dot(samples, vec4(0.25));" + // Split and average chrominance. + vec2 chrominances[4] = vec2[4]( + textureLod(qamTextureName, qamTextureCoordinates[0], 0).gb, + textureLod(qamTextureName, qamTextureCoordinates[1], 0).gb, + textureLod(qamTextureName, qamTextureCoordinates[2], 0).gb, + textureLod(qamTextureName, qamTextureCoordinates[3], 0).gb + ); + vec2 channels = (chrominances[0] + chrominances[1] + chrominances[2] + chrominances[3])*0.5 - vec2(1.0); - // Split and average chrominance. - "vec2 chrominances[4] = vec2[4](" - "textureLod(qamTextureName, qamTextureCoordinates[0], 0).gb," - "textureLod(qamTextureName, qamTextureCoordinates[1], 0).gb," - "textureLod(qamTextureName, qamTextureCoordinates[2], 0).gb," - "textureLod(qamTextureName, qamTextureCoordinates[3], 0).gb" - ");" - "vec2 channels = (chrominances[0] + chrominances[1] + chrominances[2] + chrominances[3])*0.5 - vec2(1.0);" - - // Apply a colour space conversion to get RGB. - "fragColour3 = mix(" - "lumaChromaToRGB * vec3(luminance / (1.0 - compositeAmplitude), channels)," - "vec3(mono_luminance)," - "step(oneOverCompositeAmplitude, 0.01)" - ");"; + // Apply a colour space conversion to get RGB. + fragColour3 = lumaChromaToRGB * vec3(luminance / (1.0 - compositeAmplitude), channels); + } + )x"; break; case DisplayType::CompositeMonochrome: From 5ee963062401d614abed5a75cdb5dd1b003b7e9a Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 28 Nov 2020 19:53:34 -0500 Subject: [PATCH 4/4] Use `compositeAmplitude` in favour of its reciprocal. --- Outputs/OpenGL/ScanTargetGLSLFragments.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp index 39e57218e..0404f95e8 100644 --- a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp +++ b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp @@ -391,10 +391,10 @@ std::unique_ptr ScanTarget::conversion_shader() const { ); // The outer structure of the OpenGL scan target means in practice that - // oneOverCompositeAmplitude will be the same value across a piece of + // compositeAmplitude will be the same value across a piece of // geometry. I am therefore optimistic that this conditional will not // cause a divergence in fragment execution. - if(oneOverCompositeAmplitude < 0.01) { + if(compositeAmplitude < 0.01) { // Compute only a luminance for use if there's no colour information. fragColour3 = vec3(dot(samples, vec4(0.15, 0.35, 0.35, 0.15))); } else {