2018-11-12 02:41:13 +00:00
|
|
|
//
|
|
|
|
// ScanTargetVertexArrayAttributs.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 11/11/2018.
|
|
|
|
// Copyright © 2018 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "ScanTarget.hpp"
|
|
|
|
|
2018-11-24 03:34:38 +00:00
|
|
|
#include "../../SignalProcessing/FIRFilter.hpp"
|
|
|
|
|
2018-11-12 02:41:13 +00:00
|
|
|
using namespace Outputs::Display::OpenGL;
|
|
|
|
|
2018-11-12 23:56:54 +00:00
|
|
|
std::string ScanTarget::glsl_globals(ShaderType type) {
|
2018-11-12 02:41:13 +00:00
|
|
|
switch(type) {
|
2018-11-24 03:34:38 +00:00
|
|
|
case ShaderType::InputScan:
|
|
|
|
case ShaderType::ProcessedScan:
|
2018-11-12 02:41:13 +00:00
|
|
|
return
|
2018-11-12 04:23:42 +00:00
|
|
|
"#version 150\n"
|
|
|
|
|
2018-11-12 02:41:13 +00:00
|
|
|
"uniform vec2 scale;"
|
2018-11-22 22:20:31 +00:00
|
|
|
|
2018-11-12 02:41:13 +00:00
|
|
|
"uniform mat3 lumaChromaToRGB;"
|
|
|
|
"uniform mat3 rgbToLumaChroma;"
|
2018-11-22 22:20:31 +00:00
|
|
|
|
|
|
|
"uniform float rowHeight;"
|
2018-11-14 02:15:33 +00:00
|
|
|
"uniform float processingWidth;"
|
2018-11-12 02:41:13 +00:00
|
|
|
|
|
|
|
"in vec2 startPoint;"
|
|
|
|
"in float startDataX;"
|
|
|
|
"in float startCompositeAngle;"
|
|
|
|
|
|
|
|
"in vec2 endPoint;"
|
|
|
|
"in float endDataX;"
|
|
|
|
"in float endCompositeAngle;"
|
|
|
|
|
|
|
|
"in float dataY;"
|
2018-11-22 18:22:04 +00:00
|
|
|
"in float lineY;"
|
2018-11-24 23:03:44 +00:00
|
|
|
"in float compositeAmplitude;";
|
2018-11-12 04:23:42 +00:00
|
|
|
|
2018-11-12 23:56:54 +00:00
|
|
|
case ShaderType::Line:
|
|
|
|
return
|
|
|
|
"#version 150\n"
|
|
|
|
|
|
|
|
"uniform vec2 scale;"
|
|
|
|
"uniform float rowHeight;"
|
2018-11-14 02:15:33 +00:00
|
|
|
"uniform float processingWidth;"
|
2018-11-12 23:56:54 +00:00
|
|
|
|
|
|
|
"in vec2 startPoint;"
|
2018-11-14 02:15:33 +00:00
|
|
|
"in vec2 endPoint;"
|
|
|
|
|
2018-11-22 18:22:04 +00:00
|
|
|
"in float lineY;"
|
|
|
|
|
|
|
|
"uniform sampler2D textureName;"
|
|
|
|
"uniform vec2 origin;"
|
|
|
|
"uniform vec2 size;";
|
2018-11-12 23:56:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-24 21:06:26 +00:00
|
|
|
std::vector<Shader::AttributeBinding> ScanTarget::attribute_bindings(ShaderType type) {
|
|
|
|
switch(type) {
|
|
|
|
case ShaderType::InputScan:
|
|
|
|
case ShaderType::ProcessedScan:
|
|
|
|
return {
|
|
|
|
{"startPoint", 0},
|
|
|
|
{"startDataX", 1},
|
|
|
|
{"startCompositeAngle", 2},
|
|
|
|
{"endPoint", 3},
|
|
|
|
{"endDataX", 4},
|
|
|
|
{"endCompositeAngle", 5},
|
|
|
|
{"dataY", 6},
|
|
|
|
{"lineY", 7},
|
|
|
|
{"compositeAmplitude", 8},
|
|
|
|
};
|
|
|
|
|
|
|
|
case ShaderType::Line:
|
|
|
|
return {
|
|
|
|
{"startPoint", 0},
|
|
|
|
{"endPoint", 1},
|
|
|
|
{"lineY", 2},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 02:21:54 +00:00
|
|
|
std::string ScanTarget::glsl_default_vertex_shader(ShaderType type) {
|
2018-11-13 01:15:38 +00:00
|
|
|
switch(type) {
|
2018-11-24 03:34:38 +00:00
|
|
|
case ShaderType::InputScan:
|
|
|
|
case ShaderType::ProcessedScan: {
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
if(type == ShaderType::InputScan) {
|
2018-11-24 23:03:44 +00:00
|
|
|
result +=
|
|
|
|
"out vec2 textureCoordinate;"
|
|
|
|
"uniform usampler2D textureName;";
|
2018-11-24 03:34:38 +00:00
|
|
|
} else {
|
2018-11-24 23:03:44 +00:00
|
|
|
result +=
|
|
|
|
"out vec2 textureCoordinates[11];"
|
2018-11-26 02:54:12 +00:00
|
|
|
"out vec2 combCoordinates[2];"
|
|
|
|
"uniform sampler2D textureName;"
|
|
|
|
"uniform float combOffset;";
|
2018-11-24 03:34:38 +00:00
|
|
|
}
|
2018-11-13 03:52:26 +00:00
|
|
|
|
2018-11-24 03:34:38 +00:00
|
|
|
result +=
|
|
|
|
"out float compositeAngle;"
|
2018-11-25 03:30:39 +00:00
|
|
|
"out float oneOverCompositeAmplitude;"
|
2018-11-24 03:34:38 +00:00
|
|
|
|
|
|
|
"void main(void) {"
|
|
|
|
"float lateral = float(gl_VertexID & 1);"
|
|
|
|
"float longitudinal = float((gl_VertexID & 2) >> 1);"
|
|
|
|
|
|
|
|
"compositeAngle = (mix(startCompositeAngle, endCompositeAngle, lateral) / 32.0) * 3.141592654;"
|
2018-11-25 03:30:39 +00:00
|
|
|
"oneOverCompositeAmplitude = mix(0.0, 255.0 / compositeAmplitude, step(0.01, compositeAmplitude));";
|
2018-11-24 03:34:38 +00:00
|
|
|
|
|
|
|
if(type == ShaderType::InputScan) {
|
|
|
|
result +=
|
2018-11-24 22:37:58 +00:00
|
|
|
"textureCoordinate = vec2(mix(startDataX, endDataX, lateral), dataY + 0.5) / textureSize(textureName, 0);"
|
2018-11-24 03:34:38 +00:00
|
|
|
"vec2 eyePosition = vec2(mix(startPoint.x, endPoint.x, lateral) * processingWidth, lineY + longitudinal) / vec2(scale.x, 2048.0);";
|
|
|
|
} else {
|
|
|
|
result +=
|
2018-11-24 22:37:58 +00:00
|
|
|
"vec2 sourcePosition = vec2(mix(startPoint.x, endPoint.x, lateral) * processingWidth, lineY + 0.5);"
|
|
|
|
"vec2 eyePosition = (sourcePosition + vec2(0.0, longitudinal - 0.5)) / vec2(scale.x, 2048.0);"
|
|
|
|
"sourcePosition /= vec2(scale.x, 2048.0);"
|
|
|
|
|
|
|
|
"textureCoordinates[0] = sourcePosition + vec2(-5.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[1] = sourcePosition + vec2(-4.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[2] = sourcePosition + vec2(-3.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[3] = sourcePosition + vec2(-2.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[4] = sourcePosition + vec2(-1.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[5] = sourcePosition;"
|
|
|
|
"textureCoordinates[6] = sourcePosition + vec2(1.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[7] = sourcePosition + vec2(2.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[8] = sourcePosition + vec2(3.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[9] = sourcePosition + vec2(4.0, 0.0) / textureSize(textureName, 0);"
|
|
|
|
"textureCoordinates[10] = sourcePosition + vec2(5.0, 0.0) / textureSize(textureName, 0);"
|
2018-11-24 21:06:26 +00:00
|
|
|
|
2018-11-26 02:54:12 +00:00
|
|
|
"combCoordinates[0] = sourcePosition - vec2(combOffset, 0.0);"
|
|
|
|
"combCoordinates[1] = sourcePosition + vec2(combOffset, 0.0);"
|
|
|
|
|
2018-11-24 21:06:26 +00:00
|
|
|
"eyePosition = eyePosition;";
|
2018-11-24 03:34:38 +00:00
|
|
|
}
|
2018-11-13 03:52:26 +00:00
|
|
|
|
2018-11-24 03:34:38 +00:00
|
|
|
return result +
|
|
|
|
"gl_Position = vec4(eyePosition*2.0 - vec2(1.0), 0.0, 1.0);"
|
|
|
|
"}";
|
|
|
|
}
|
2018-11-13 01:15:38 +00:00
|
|
|
|
|
|
|
case ShaderType::Line:
|
2018-11-12 23:56:54 +00:00
|
|
|
return
|
2018-11-14 02:15:33 +00:00
|
|
|
"out vec2 textureCoordinate;"
|
|
|
|
|
2018-11-12 04:23:42 +00:00
|
|
|
"void main(void) {"
|
|
|
|
"float lateral = float(gl_VertexID & 1);"
|
|
|
|
"float longitudinal = float((gl_VertexID & 2) >> 1);"
|
|
|
|
|
2018-11-17 22:31:32 +00:00
|
|
|
"textureCoordinate = vec2(lateral * processingWidth, lineY + 0.5) / vec2(1.0, textureSize(textureName, 0).y);"
|
2018-11-14 02:15:33 +00:00
|
|
|
|
2018-11-12 23:23:45 +00:00
|
|
|
"vec2 centrePoint = mix(startPoint, endPoint, lateral) / scale;"
|
|
|
|
"vec2 height = normalize(endPoint - startPoint).yx * (longitudinal - 0.5) * rowHeight;"
|
2018-11-22 18:22:04 +00:00
|
|
|
"vec2 eyePosition = vec2(-1.0, 1.0) + vec2(2.0, -2.0) * (((centrePoint + height) - origin) / size);"
|
2018-11-12 23:28:09 +00:00
|
|
|
"gl_Position = vec4(eyePosition, 0.0, 1.0);"
|
2018-11-12 04:23:42 +00:00
|
|
|
"}";
|
2018-11-13 01:15:38 +00:00
|
|
|
}
|
2018-11-12 02:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScanTarget::enable_vertex_attributes(ShaderType type, Shader &target) {
|
|
|
|
switch(type) {
|
2018-11-24 03:34:38 +00:00
|
|
|
case ShaderType::InputScan:
|
|
|
|
case ShaderType::ProcessedScan:
|
2018-11-12 02:41:13 +00:00
|
|
|
for(int c = 0; c < 2; ++c) {
|
|
|
|
const std::string prefix = c ? "end" : "start";
|
|
|
|
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
prefix + "Point",
|
|
|
|
2, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, scan.end_points[c].x)),
|
|
|
|
1);
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
prefix + "DataX",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, scan.end_points[c].data_offset)),
|
|
|
|
1);
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
prefix + "CompositeAngle",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, scan.end_points[c].composite_angle)),
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
"dataY",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, data_y)),
|
|
|
|
1);
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
"lineY",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, line)),
|
|
|
|
1);
|
2018-11-22 22:20:31 +00:00
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
"compositeAmplitude",
|
|
|
|
1, GL_UNSIGNED_BYTE, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, scan.composite_amplitude)),
|
|
|
|
1);
|
2018-11-12 02:41:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ShaderType::Line:
|
|
|
|
for(int c = 0; c < 2; ++c) {
|
|
|
|
const std::string prefix = c ? "end" : "start";
|
|
|
|
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
prefix + "Point",
|
|
|
|
2, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Line),
|
|
|
|
reinterpret_cast<void *>(offsetof(Line, end_points[c].x)),
|
|
|
|
1);
|
|
|
|
}
|
2018-11-14 02:15:33 +00:00
|
|
|
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
"lineY",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Line),
|
|
|
|
reinterpret_cast<void *>(offsetof(Line, line)),
|
|
|
|
1);
|
2018-11-12 02:41:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 02:02:46 +00:00
|
|
|
|
2018-11-22 19:36:46 +00:00
|
|
|
std::unique_ptr<Shader> ScanTarget::input_shader(InputDataType input_data_type, DisplayType display_type) {
|
2018-11-16 02:02:46 +00:00
|
|
|
std::string fragment_shader =
|
|
|
|
"#version 150\n"
|
|
|
|
|
2018-11-24 22:37:58 +00:00
|
|
|
"out vec3 fragColour;"
|
2018-11-22 22:20:31 +00:00
|
|
|
"in vec2 textureCoordinate;"
|
|
|
|
"in float compositeAngle;"
|
2018-11-25 03:30:39 +00:00
|
|
|
"in float oneOverCompositeAmplitude;"
|
2018-11-22 22:20:31 +00:00
|
|
|
|
|
|
|
"uniform mat3 lumaChromaToRGB;"
|
|
|
|
"uniform mat3 rgbToLumaChroma;"
|
|
|
|
"uniform usampler2D textureName;"
|
|
|
|
|
|
|
|
"void main(void) {";
|
2018-11-16 02:02:46 +00:00
|
|
|
|
2018-11-22 22:20:31 +00:00
|
|
|
DisplayType computed_display_type;
|
2018-11-16 02:02:46 +00:00
|
|
|
switch(input_data_type) {
|
|
|
|
case InputDataType::Luminance1:
|
2018-11-22 22:20:31 +00:00
|
|
|
computed_display_type = DisplayType::CompositeMonochrome;
|
2018-11-24 22:37:58 +00:00
|
|
|
fragment_shader += "fragColour = texture(textureName, textureCoordinate).rrr;";
|
2018-11-25 02:30:09 +00:00
|
|
|
|
|
|
|
if(computed_display_type != display_type) {
|
|
|
|
fragment_shader += "fragColour = clamp(fragColour, 0.0, 1.0);";
|
|
|
|
}
|
2018-11-16 02:02:46 +00:00
|
|
|
break;
|
|
|
|
|
2018-11-16 02:21:54 +00:00
|
|
|
case InputDataType::Luminance8:
|
2018-11-22 22:20:31 +00:00
|
|
|
computed_display_type = DisplayType::CompositeMonochrome;
|
2018-11-24 22:37:58 +00:00
|
|
|
fragment_shader += "fragColour = vec3(texture(textureName, textureCoordinate).r / 255.0);";
|
2018-11-16 02:21:54 +00:00
|
|
|
break;
|
|
|
|
|
2018-11-23 03:43:42 +00:00
|
|
|
case InputDataType::Luminance8Phase8:
|
2018-11-22 22:20:31 +00:00
|
|
|
computed_display_type = DisplayType::SVideo;
|
2018-11-23 03:43:42 +00:00
|
|
|
fragment_shader +=
|
|
|
|
"vec2 yc = texture(textureName, textureCoordinate).rg / vec2(255.0);"
|
|
|
|
|
|
|
|
"float phaseOffset = 3.141592654 * 2.0 * 2.0 * yc.y;"
|
2018-11-25 02:40:34 +00:00
|
|
|
"float rawChroma = step(yc.y, 0.75) * cos(compositeAngle + phaseOffset);"
|
|
|
|
"fragColour = vec3(yc.x, 0.5 + rawChroma*0.5, 0.0);";
|
2018-11-22 22:20:31 +00:00
|
|
|
break;
|
2018-11-16 02:32:22 +00:00
|
|
|
|
2018-11-16 02:02:46 +00:00
|
|
|
case InputDataType::Red1Green1Blue1:
|
2018-11-22 22:20:31 +00:00
|
|
|
computed_display_type = DisplayType::RGB;
|
2018-11-16 02:02:46 +00:00
|
|
|
fragment_shader +=
|
2018-11-22 22:20:31 +00:00
|
|
|
"uint textureValue = texture(textureName, textureCoordinate).r;"
|
2018-11-24 22:37:58 +00:00
|
|
|
"fragColour = uvec3(textureValue) & uvec3(4u, 2u, 1u);";
|
2018-11-25 02:30:09 +00:00
|
|
|
|
|
|
|
if(computed_display_type != display_type) {
|
|
|
|
fragment_shader += "fragColour = clamp(fragColour, 0.0, 1.0);";
|
|
|
|
}
|
2018-11-16 02:02:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputDataType::Red2Green2Blue2:
|
2018-11-22 22:20:31 +00:00
|
|
|
computed_display_type = DisplayType::RGB;
|
2018-11-16 02:32:22 +00:00
|
|
|
fragment_shader +=
|
2018-11-22 22:20:31 +00:00
|
|
|
"uint textureValue = texture(textureName, textureCoordinate).r;"
|
2018-11-24 22:37:58 +00:00
|
|
|
"fragColour = vec3(float((textureValue >> 4) & 3u), float((textureValue >> 2) & 3u), float(textureValue & 3u)) / 3.0;";
|
2018-11-16 02:02:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputDataType::Red4Green4Blue4:
|
2018-11-22 22:20:31 +00:00
|
|
|
computed_display_type = DisplayType::RGB;
|
|
|
|
fragment_shader +=
|
|
|
|
"uvec2 textureValue = texture(textureName, textureCoordinate).rg;"
|
2018-11-24 22:37:58 +00:00
|
|
|
"fragColour = vec3(float(textureValue.r) / 15.0, float(textureValue.g & 240u) / 240.0, float(textureValue.g & 15u) / 15.0);";
|
2018-11-16 02:02:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputDataType::Red8Green8Blue8:
|
2018-11-22 22:20:31 +00:00
|
|
|
computed_display_type = DisplayType::RGB;
|
2018-11-24 22:37:58 +00:00
|
|
|
fragment_shader += "fragColour = texture(textureName, textureCoordinate).rgb / vec3(255.0);";
|
2018-11-16 02:02:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-25 02:40:34 +00:00
|
|
|
// If the input type is RGB but the output type isn't then
|
|
|
|
// there'll definitely be an RGB to SVideo step.
|
|
|
|
if(computed_display_type == DisplayType::RGB && display_type != DisplayType::RGB) {
|
|
|
|
fragment_shader +=
|
|
|
|
"vec3 composite_colour = rgbToLumaChroma * fragColour;"
|
|
|
|
"vec2 quadrature = vec2(cos(compositeAngle), sin(compositeAngle));"
|
|
|
|
"fragColour = vec3(composite_colour.r, 0.5 + dot(quadrature, composite_colour.gb)*0.5, 0.0);";
|
|
|
|
}
|
2018-11-22 22:20:31 +00:00
|
|
|
|
2018-11-25 02:40:34 +00:00
|
|
|
// If the output type is SVideo, throw in an attempt to separate the two chrominance
|
2018-11-25 02:55:15 +00:00
|
|
|
// channels here.
|
2018-11-25 02:40:34 +00:00
|
|
|
if(display_type == DisplayType::SVideo) {
|
|
|
|
if(computed_display_type != DisplayType::RGB) {
|
2018-11-24 23:51:07 +00:00
|
|
|
fragment_shader +=
|
2018-11-25 02:40:34 +00:00
|
|
|
"vec2 quadrature = vec2(cos(compositeAngle), sin(compositeAngle));";
|
2018-11-22 22:20:31 +00:00
|
|
|
}
|
2018-11-25 02:40:34 +00:00
|
|
|
fragment_shader +=
|
|
|
|
"vec2 chroma = (((fragColour.y - 0.5)*2.0) * quadrature)*0.5 + vec2(0.5);"
|
|
|
|
"fragColour = vec3(fragColour.x, chroma);";
|
|
|
|
}
|
|
|
|
|
2018-11-25 02:55:15 +00:00
|
|
|
// Add an SVideo to composite step if necessary.
|
2018-11-25 02:40:34 +00:00
|
|
|
if(
|
|
|
|
(display_type == DisplayType::CompositeMonochrome || display_type == DisplayType::CompositeColour) &&
|
|
|
|
computed_display_type != DisplayType::CompositeMonochrome
|
|
|
|
) {
|
2018-11-25 03:30:39 +00:00
|
|
|
fragment_shader += "fragColour = vec3(mix(fragColour.r, 2.0*(fragColour.g - 0.5), 1.0 / oneOverCompositeAmplitude));";
|
2018-11-22 22:20:31 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 02:02:46 +00:00
|
|
|
return std::unique_ptr<Shader>(new Shader(
|
2018-11-24 03:34:38 +00:00
|
|
|
glsl_globals(ShaderType::InputScan) + glsl_default_vertex_shader(ShaderType::InputScan),
|
2018-11-24 21:06:26 +00:00
|
|
|
fragment_shader + "}",
|
|
|
|
attribute_bindings(ShaderType::InputScan)
|
2018-11-16 02:02:46 +00:00
|
|
|
));
|
|
|
|
}
|
2018-11-24 03:34:38 +00:00
|
|
|
|
2018-11-25 03:30:39 +00:00
|
|
|
std::vector<float> ScanTarget::coefficients_for_filter(int colour_cycle_numerator, int colour_cycle_denominator, int processing_width, float multiple_of_colour_clock) {
|
|
|
|
const float cycles_per_expanded_line = (float(colour_cycle_numerator) / float(colour_cycle_denominator)) / (float(processing_width) / float(LineBufferWidth));
|
|
|
|
const SignalProcessing::FIRFilter filter(11, float(LineBufferWidth), 0.0f, cycles_per_expanded_line * multiple_of_colour_clock);
|
|
|
|
return filter.get_coefficients();
|
|
|
|
}
|
|
|
|
|
2018-11-24 03:54:52 +00:00
|
|
|
std::unique_ptr<Shader> ScanTarget::svideo_to_rgb_shader(int colour_cycle_numerator, int colour_cycle_denominator, int processing_width) {
|
2018-11-24 03:34:38 +00:00
|
|
|
/*
|
|
|
|
Composite to S-Video conversion is achieved by filtering the input signal to obtain luminance, and then subtracting that
|
|
|
|
from the original to get chrominance.
|
|
|
|
|
|
|
|
(Colour cycle numerator)/(Colour cycle denominator) gives the number of colour cycles in (processing_width / LineBufferWidth),
|
|
|
|
there'll be at least four samples per colour clock and in practice at most just a shade more than 9.
|
|
|
|
*/
|
|
|
|
auto shader = std::unique_ptr<Shader>(new Shader(
|
|
|
|
glsl_globals(ShaderType::ProcessedScan) + glsl_default_vertex_shader(ShaderType::ProcessedScan),
|
|
|
|
"#version 150\n"
|
|
|
|
|
|
|
|
"in vec2 textureCoordinates[11];"
|
2018-11-26 02:54:12 +00:00
|
|
|
"uniform vec4 chromaWeights[3];"
|
|
|
|
"uniform vec4 lumaWeights[3];"
|
2018-11-24 23:03:44 +00:00
|
|
|
"uniform sampler2D textureName;"
|
2018-11-24 23:51:07 +00:00
|
|
|
"uniform mat3 lumaChromaToRGB;"
|
2018-11-24 03:34:38 +00:00
|
|
|
|
2018-11-24 22:37:58 +00:00
|
|
|
"out vec3 fragColour;"
|
2018-11-24 23:51:07 +00:00
|
|
|
"void main() {"
|
|
|
|
"vec3 samples[11] = vec3[11]("
|
|
|
|
"texture(textureName, textureCoordinates[0]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[1]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[2]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[3]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[4]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[5]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[6]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[7]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[8]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[9]).rgb,"
|
|
|
|
"texture(textureName, textureCoordinates[10]).rgb"
|
|
|
|
");"
|
2018-11-26 02:54:12 +00:00
|
|
|
"vec4 samples0[3] = vec4[3]("
|
|
|
|
"vec4(samples[0].r, samples[1].r, samples[2].r, samples[3].r),"
|
|
|
|
"vec4(samples[4].r, samples[5].r, samples[6].r, samples[7].r),"
|
|
|
|
"vec4(samples[8].r, samples[9].r, samples[10].r, 0.0)"
|
|
|
|
");"
|
2018-11-24 23:51:07 +00:00
|
|
|
"vec4 samples1[3] = vec4[3]("
|
|
|
|
"vec4(samples[0].g, samples[1].g, samples[2].g, samples[3].g),"
|
|
|
|
"vec4(samples[4].g, samples[5].g, samples[6].g, samples[7].g),"
|
|
|
|
"vec4(samples[8].g, samples[9].g, samples[10].g, 0.0)"
|
|
|
|
");"
|
|
|
|
"vec4 samples2[3] = vec4[3]("
|
|
|
|
"vec4(samples[0].b, samples[1].b, samples[2].b, samples[3].b),"
|
|
|
|
"vec4(samples[4].b, samples[5].b, samples[6].b, samples[7].b),"
|
|
|
|
"vec4(samples[8].b, samples[9].b, samples[10].b, 0.0)"
|
|
|
|
");"
|
2018-11-26 02:54:12 +00:00
|
|
|
"float channel0 = dot(lumaWeights[0], samples0[0]) + dot(lumaWeights[1], samples0[1]) + dot(lumaWeights[2], samples0[2]);"
|
|
|
|
"float channel1 = dot(chromaWeights[0], samples1[0]) + dot(chromaWeights[1], samples1[1]) + dot(chromaWeights[2], samples1[2]);"
|
|
|
|
"float channel2 = dot(chromaWeights[0], samples2[0]) + dot(chromaWeights[1], samples2[1]) + dot(chromaWeights[2], samples2[2]);"
|
2018-11-25 02:30:09 +00:00
|
|
|
"vec2 chroma = vec2(channel1, channel2)*2.0 - vec2(1.0);"
|
2018-11-26 02:54:12 +00:00
|
|
|
"fragColour = lumaChromaToRGB * vec3(channel0, chroma);"
|
2018-11-24 21:06:26 +00:00
|
|
|
"}",
|
|
|
|
attribute_bindings(ShaderType::ProcessedScan)
|
2018-11-24 03:34:38 +00:00
|
|
|
));
|
2018-11-25 02:30:09 +00:00
|
|
|
|
2018-11-26 02:54:12 +00:00
|
|
|
auto chroma_coefficients = coefficients_for_filter(colour_cycle_numerator, colour_cycle_denominator, processing_width, 0.25f);
|
|
|
|
chroma_coefficients.push_back(0.0f);
|
|
|
|
shader->set_uniform("chromaWeights", 4, 3, chroma_coefficients.data());
|
|
|
|
|
|
|
|
auto luma_coefficients = coefficients_for_filter(colour_cycle_numerator, colour_cycle_denominator, processing_width, 0.5f);
|
|
|
|
luma_coefficients.push_back(0.0f);
|
|
|
|
shader->set_uniform("lumaWeights", 4, 3, luma_coefficients.data());
|
2018-11-25 02:30:09 +00:00
|
|
|
|
2018-11-24 03:34:38 +00:00
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2018-11-24 03:54:52 +00:00
|
|
|
std::unique_ptr<Shader> ScanTarget::composite_to_svideo_shader(int colour_cycle_numerator, int colour_cycle_denominator, int processing_width) {
|
2018-11-25 03:30:39 +00:00
|
|
|
auto shader = std::unique_ptr<Shader>(new Shader(
|
|
|
|
glsl_globals(ShaderType::ProcessedScan) + glsl_default_vertex_shader(ShaderType::ProcessedScan),
|
|
|
|
"#version 150\n"
|
|
|
|
|
|
|
|
"in vec2 textureCoordinates[11];"
|
2018-11-26 02:54:12 +00:00
|
|
|
"in vec2 combCoordinates[2];"
|
2018-11-25 03:30:39 +00:00
|
|
|
"in float compositeAngle;"
|
|
|
|
"in float oneOverCompositeAmplitude;"
|
|
|
|
|
|
|
|
"uniform vec4 textureWeights[3];"
|
|
|
|
"uniform sampler2D textureName;"
|
|
|
|
|
|
|
|
"out vec3 fragColour;"
|
|
|
|
"void main() {"
|
2018-11-26 02:54:12 +00:00
|
|
|
"float luma = mix(texture(textureName, combCoordinates[0]).r, texture(textureName, combCoordinates[1]).r, 0.5);"
|
|
|
|
"float centre = texture(textureName, textureCoordinates[5]).r;"
|
2018-11-25 03:30:39 +00:00
|
|
|
"vec2 quadrature = vec2(cos(compositeAngle), sin(compositeAngle));"
|
2018-11-26 02:54:12 +00:00
|
|
|
"vec2 chroma = ((centre - luma) * oneOverCompositeAmplitude)*quadrature;"
|
2018-11-25 03:30:39 +00:00
|
|
|
"fragColour = vec3(luma, chroma*0.5 + vec2(0.5));"
|
|
|
|
"}",
|
|
|
|
attribute_bindings(ShaderType::ProcessedScan)
|
|
|
|
));
|
|
|
|
|
2018-11-26 02:54:12 +00:00
|
|
|
const float cycles_per_expanded_line = (float(colour_cycle_numerator) / float(colour_cycle_denominator)) / (float(processing_width) / float(LineBufferWidth));
|
|
|
|
float quarter_distancce = 0.25f / cycles_per_expanded_line;
|
|
|
|
shader->set_uniform("combOffset", quarter_distancce);
|
2018-11-25 03:30:39 +00:00
|
|
|
|
|
|
|
return shader;
|
2018-11-24 03:34:38 +00:00
|
|
|
}
|