46 lines
1.5 KiB
GLSL
46 lines
1.5 KiB
GLSL
#version 330 core
|
|
// Or appropriate GLSL version
|
|
|
|
out vec4 FragColor;
|
|
|
|
in vec2 TexCoords; // Comes from passthrough.vert
|
|
|
|
uniform sampler2D texBefore;
|
|
uniform sampler2D texAfter;
|
|
|
|
uniform float diffBoost = 5.0; // Uniform to control contrast boost
|
|
|
|
// Basic Luma calculation (Rec.709)
|
|
float Luma(vec3 color) {
|
|
return dot(color, vec3(0.2126, 0.7152, 0.0722));
|
|
}
|
|
|
|
void main() {
|
|
vec3 colorBefore = texture(texBefore, TexCoords).rgb;
|
|
vec3 colorAfter = texture(texAfter, TexCoords).rgb;
|
|
|
|
// Calculate absolute difference per channel
|
|
vec3 diff = abs(colorAfter - colorBefore);
|
|
|
|
// Calculate average difference or luma difference (luma might be better)
|
|
// float avgDiff = (diff.r + diff.g + diff.b) / 3.0;
|
|
float lumaDiff = abs(Luma(colorAfter) - Luma(colorBefore));
|
|
|
|
// Boost the difference for visibility and clamp
|
|
float boostedDiff = clamp(lumaDiff * diffBoost, 0.0, 1.0);
|
|
|
|
// Output as grayscale
|
|
FragColor = vec4(vec3(boostedDiff), 1.0);
|
|
|
|
// --- Alternative Visualizations ---
|
|
// // Simple Red highlight for changes:
|
|
// if (boostedDiff > 0.05) { // Threshold
|
|
// FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
|
// } else {
|
|
// FragColor = vec4(colorBefore, 1.0); // Show original where no change
|
|
// }
|
|
|
|
// // False color based on difference magnitude (example):
|
|
// vec3 diffColor = vec3(boostedDiff * 2.0, (1.0 - boostedDiff) * 2.0, 0.0); // Example: Red=High diff, Green=Low diff
|
|
// FragColor = vec4(clamp(diffColor, 0.0, 1.0), 1.0);
|
|
} |