mirror of
https://github.com/TomHarte/CLK.git
synced 2024-09-11 22:56:20 +00:00
Merge pull request #854 from TomHarte/OpenGLNoColourBurst
Avoids all risk of infinities when there is no colour burst
This commit is contained in:
commit
9610672615
@ -341,7 +341,7 @@ std::unique_ptr<Shader> ScanTarget::conversion_shader() const {
|
|||||||
vertex_shader +=
|
vertex_shader +=
|
||||||
"compositeAngle = (mix(startCompositeAngle, endCompositeAngle, lateral) / 32.0) * 3.141592654;"
|
"compositeAngle = (mix(startCompositeAngle, endCompositeAngle, lateral) / 32.0) * 3.141592654;"
|
||||||
"compositeAmplitude = lineCompositeAmplitude / 255.0;"
|
"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 +=
|
vertex_shader +=
|
||||||
@ -379,40 +379,42 @@ std::unique_ptr<Shader> ScanTarget::conversion_shader() const {
|
|||||||
|
|
||||||
switch(modals.display_type) {
|
switch(modals.display_type) {
|
||||||
case DisplayType::CompositeColour:
|
case DisplayType::CompositeColour:
|
||||||
fragment_shader +=
|
fragment_shader += R"x(
|
||||||
"vec4 angles = compositeAngle + compositeAngleOffsets;"
|
vec4 angles = compositeAngle + compositeAngleOffsets;
|
||||||
|
|
||||||
// Sample four times over, at proper angle offsets.
|
// Sample four times over, at proper angle offsets.
|
||||||
"vec4 samples = vec4("
|
vec4 samples = vec4(
|
||||||
"composite_sample(textureCoordinates[0], angles.x),"
|
composite_sample(textureCoordinates[0], angles.x),
|
||||||
"composite_sample(textureCoordinates[1], angles.y),"
|
composite_sample(textureCoordinates[1], angles.y),
|
||||||
"composite_sample(textureCoordinates[2], angles.z),"
|
composite_sample(textureCoordinates[2], angles.z),
|
||||||
"composite_sample(textureCoordinates[3], angles.w)"
|
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
|
||||||
|
// 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(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 {
|
||||||
// Take the average to calculate luminance, then subtract that from all four samples to
|
// Take the average to calculate luminance, then subtract that from all four samples to
|
||||||
// give chrominance.
|
// give chrominance.
|
||||||
"float luminance = dot(samples, vec4(0.25));"
|
float luminance = dot(samples, vec4(0.25));
|
||||||
|
|
||||||
// Split and average chrominance.
|
// Split and average chrominance.
|
||||||
"vec2 chrominances[4] = vec2[4]("
|
vec2 chrominances[4] = vec2[4](
|
||||||
"textureLod(qamTextureName, qamTextureCoordinates[0], 0).gb,"
|
textureLod(qamTextureName, qamTextureCoordinates[0], 0).gb,
|
||||||
"textureLod(qamTextureName, qamTextureCoordinates[1], 0).gb,"
|
textureLod(qamTextureName, qamTextureCoordinates[1], 0).gb,
|
||||||
"textureLod(qamTextureName, qamTextureCoordinates[2], 0).gb,"
|
textureLod(qamTextureName, qamTextureCoordinates[2], 0).gb,
|
||||||
"textureLod(qamTextureName, qamTextureCoordinates[3], 0).gb"
|
textureLod(qamTextureName, qamTextureCoordinates[3], 0).gb
|
||||||
");"
|
);
|
||||||
"vec2 channels = (chrominances[0] + chrominances[1] + chrominances[2] + chrominances[3])*0.5 - vec2(1.0);"
|
vec2 channels = (chrominances[0] + chrominances[1] + chrominances[2] + chrominances[3])*0.5 - vec2(1.0);
|
||||||
|
|
||||||
// Apply a colour space conversion to get RGB.
|
// Apply a colour space conversion to get RGB.
|
||||||
"fragColour3 = mix("
|
fragColour3 = lumaChromaToRGB * vec3(luminance / (1.0 - compositeAmplitude), channels);
|
||||||
"lumaChromaToRGB * vec3(luminance / (1.0 - compositeAmplitude), channels),"
|
}
|
||||||
"vec3(mono_luminance),"
|
)x";
|
||||||
"step(oneOverCompositeAmplitude, 0.01)"
|
|
||||||
");";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DisplayType::CompositeMonochrome:
|
case DisplayType::CompositeMonochrome:
|
||||||
@ -622,7 +624,7 @@ std::unique_ptr<Shader> ScanTarget::qam_separation_shader() const {
|
|||||||
|
|
||||||
"compositeAngle = compositeAngle * 2.0 * 3.141592654;"
|
"compositeAngle = compositeAngle * 2.0 * 3.141592654;"
|
||||||
"compositeAmplitude = lineCompositeAmplitude / 255.0;"
|
"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) {
|
if(is_svideo) {
|
||||||
vertex_shader +=
|
vertex_shader +=
|
||||||
|
Loading…
Reference in New Issue
Block a user