it is still asking for 2 sources?!?!?! it should automatically get the incoming stream and filter it accordingly!! please read the repo again and then fix the CODE accordinfgly: https://github.com/exeldro/obs-shaderfilter
CODE:
// This shader provides a "super smooth" motion effect, similar to motion blur
// or frame blending, by mixing the current frame with the previous one.
// It is optimized to only apply the blending where there is significant
// movement, making it efficient for static scenes.
// OBS Shaderfilter uses an HLSL-like syntax for its shaders,
// so standard GLSL functions like 'texture()' are replaced with '.Sample()'.
// Define the structure for vertex data, including position and texture coordinates.
// 'TEXCOORD0' is the semantic for the primary texture coordinates.
struct VertData {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
// Uniforms provided by the OBS Shaderfilter plugin:
// 'image' is the current video frame (texture) being processed by this filter.
uniform texture2d image;
// 'prevous_output' is the output of this filter from the previous frame.
// This is crucial for motion effects and is automatically populated by the plugin.
uniform texture2d prevous_output; // Corrected: Changed from 'prevous_image' to 'prevous_output'
// 'textureSampler' is the sampler state used for sampling textures.
uniform SamplerState textureSampler;
// 'image_size' gives the dimensions (width, height) of the input image.
uniform float2 image_size;
// Custom uniforms for user control, which will appear in the OBS filter properties:
// 'blend_factor': Controls the intensity of the blending.
// A value of 0.0 means only the previous frame is shown.
// A value of 1.0 means only the current frame is shown.
// For a "smooth" or "motion blur" feel, a value slightly above 0.5
// (e.g., 0.6 to 0.8) is often effective, leaning towards the current frame
// but incorporating the previous.
uniform float blend_factor = 0.7; // Default value set for smooth blending
// 'diff_threshold': Determines how much difference between current and previous
// pixels is required to trigger blending.
// If the difference is below this threshold, no blending occurs for that pixel.
// This makes the shader efficient for static scenes or parts of the scene.
// A small value (e.g., 0.01) means only very similar pixels are skipped.
// A larger value will skip blending for areas with minor changes.
uniform float diff_threshold = 0.02; // Default value set for efficiency in static areas
// The main entry point for the pixel shader.
// It takes vertex data and returns the final color for the pixel.
float4 mainImage(VertData v_in) : TARGET {
// Get the texture coordinates from the input vertex data.
float2 uv = v_in.uv;
// Sample the color from the current frame using the .Sample() method.
float4 current_color = image.Sample(textureSampler, uv);
// Sample the color from the previous frame's output using the .Sample() method.
float4 prev_color = prevous_output.Sample(textureSampler, uv); // Corrected: Using 'prevous_output'
// Calculate the Euclidean distance between the RGB components of the
// current and previous pixel colors. This gives us a measure of change.
// We ignore the alpha channel for this difference calculation as it's
// usually about color change.
float diff = distance(current_color.rgb, prev_color.rgb);
// Conditional blending logic for efficiency and smart smoothing:
// If the difference between the current and previous pixel color is
// below the defined 'diff_threshold', we consider the pixel to be
// static or have negligible change. In this case, no blending is needed.
if (diff < diff_threshold) {
// Output the current frame's color directly. This avoids blurring
// static parts of the image and saves computation.
return current_color;
} else {
// If there's a significant change (motion or color shift),
// blend the current and previous frames using the 'lerp' (linear interpolate) function.
// 'lerp(x, y, a)' calculates x * (1.0 - a) + y * a, similar to GLSL's 'mix'.
return lerp(prev_color, current_color, blend_factor);
}
}