Commands/Shaders/Get-OBSRgbColorWheelShader.ps1
function Get-OBSRgbColorWheelShader { [Alias('Set-OBSRgbColorWheelShader','Add-OBSRgbColorWheelShader')] param( # Set the speed of OBSRgbColorWheelShader [ComponentModel.DefaultBindingProperty('speed')] [Single] $Speed, # Set the color_depth of OBSRgbColorWheelShader [Alias('color_depth')] [ComponentModel.DefaultBindingProperty('color_depth')] [Single] $ColorDepth, # Set the Apply_To_Image of OBSRgbColorWheelShader [Alias('Apply_To_Image')] [ComponentModel.DefaultBindingProperty('Apply_To_Image')] [Management.Automation.SwitchParameter] $ApplyToImage, # Set the Replace_Image_Color of OBSRgbColorWheelShader [Alias('Replace_Image_Color')] [ComponentModel.DefaultBindingProperty('Replace_Image_Color')] [Management.Automation.SwitchParameter] $ReplaceImageColor, # Set the Apply_To_Specific_Color of OBSRgbColorWheelShader [Alias('Apply_To_Specific_Color')] [ComponentModel.DefaultBindingProperty('Apply_To_Specific_Color')] [Management.Automation.SwitchParameter] $ApplyToSpecificColor, # Set the Color_To_Replace of OBSRgbColorWheelShader [Alias('Color_To_Replace')] [ComponentModel.DefaultBindingProperty('Color_To_Replace')] [String] $ColorToReplace, # Set the Alpha_Percentage of OBSRgbColorWheelShader [Alias('Alpha_Percentage')] [ComponentModel.DefaultBindingProperty('Alpha_Percentage')] [Single] $AlphaPercentage, # Set the center_width_percentage of OBSRgbColorWheelShader [Alias('center_width_percentage')] [ComponentModel.DefaultBindingProperty('center_width_percentage')] [Int32] $CenterWidthPercentage, # Set the center_height_percentage of OBSRgbColorWheelShader [Alias('center_height_percentage')] [ComponentModel.DefaultBindingProperty('center_height_percentage')] [Int32] $CenterHeightPercentage, # The name of the source. This must be provided when adding an item for the first time [Parameter(ValueFromPipelineByPropertyName)] [Alias('SceneItemName')] [String] $SourceName, # The name of the filter. If this is not provided, this will default to the shader name. [Parameter(ValueFromPipelineByPropertyName)] [String] $FilterName, # The inline value of the shader. This will normally be provided as a default parameter, based off of the name. [Alias('ShaderContent')] [String] $ShaderText, # If set, will force the recreation of a shader that already exists [Management.Automation.SwitchParameter] $Force, # If set, will pass thru the commands that would be sent to OBS (these can be sent at any time with Send-OBS) [Management.Automation.SwitchParameter] $PassThru, # If set, will not wait for a response from OBS (this will be faster, but will not return anything) [Management.Automation.SwitchParameter] $NoResponse, # If set, use the shader elapsed time, instead of the OBS system elapsed time [ComponentModel.DefaultBindingProperty('use_shader_elapsed_time')] [Management.Automation.SwitchParameter] $UseShaderTime ) process { $shaderName = 'rgb_color_wheel' $ShaderNoun = 'OBSRgbColorWheelShader' if (-not $psBoundParameters['ShaderText']) { $psBoundParameters['ShaderText'] = $ShaderText = ' // RGB Color Wheel shader by Charles Fettinger for obs-shaderfilter plugin 5/2020 // https://github.com/Oncorporation/obs-shaderfilter //Converted to OpenGl by Q-mii & Exeldro February 25, 2022 uniform float speed< string label = "Speed"; string widget_type = "slider"; float minimum = 0.0; float maximum = 15.0; float step = 0.1; > = 2.0; uniform float color_depth< string label = "Color Depth"; string widget_type = "slider"; float minimum = 0.0; float maximum = 10.0; float step = 0.1; > = 2.10; uniform bool Apply_To_Image; uniform bool Replace_Image_Color; uniform bool Apply_To_Specific_Color; uniform float4 Color_To_Replace; uniform float Alpha_Percentage< string label = "Alpha Percentage"; string widget_type = "slider"; float minimum = 0.0; float maximum = 100.0; float step = 0.1; > = 100; //<Range(0.0,100.0)> uniform int center_width_percentage< string label = "center width percentage"; string widget_type = "slider"; int minimum = 0; int maximum = 100; int step = 1; > = 50; uniform int center_height_percentage< string label = "center height percentage"; string widget_type = "slider"; int minimum = 0; int maximum = 100; int step = 1; > = 50; float3 hsv2rgb(float3 c) { float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www); return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y); } float mod(float x, float y) { return x - y * floor(x / y); } float4 mainImage(VertData v_in) : TARGET { const float PI = 3.14159265f;//acos(-1); float PI180th = 0.0174532925; //PI divided by 180 float4 rgba = image.Sample(textureSampler, v_in.uv); float2 center_pixel_coordinates = float2((center_width_percentage * 0.01), (center_height_percentage * 0.01) ); float2 st = v_in.uv* uv_scale; float2 toCenter = center_pixel_coordinates - st ; float r = length(toCenter) * color_depth; float angle = atan2(toCenter.y ,toCenter.x ); float angleMod = (elapsed_time * mod(speed ,18)) / 18; rgba.rgb = hsv2rgb(float3((angle / PI*0.5) + angleMod,r,1.0)); float4 color; float4 original_color; if (Apply_To_Image) { color = image.Sample(textureSampler, v_in.uv); original_color = color; float luma = color.r * 0.299 + color.g * 0.587 + color.b * 0.114; if (Replace_Image_Color) color = float4(luma, luma, luma, luma); rgba = lerp(original_color, rgba * color,clamp(Alpha_Percentage *.01 ,0,1.0)); } if (Apply_To_Specific_Color) { color = image.Sample(textureSampler, v_in.uv); original_color = color; color = (distance(color.rgb, Color_To_Replace.rgb) <= 0.075) ? rgba : color; rgba = lerp(original_color, color, clamp(Alpha_Percentage * .01, 0, 1.0)); } return rgba; } ' } $MyVerb, $myNoun = $MyInvocation.InvocationName -split '-',2 if (-not $myNoun) { $myNoun = $myVerb $myVerb = 'Get' } switch -regex ($myVerb) { Get { $FilterNamePattern = "(?>$( if ($FilterName) { [Regex]::Escape($FilterName) } else { [Regex]::Escape($ShaderNoun -replace '^OBS' -replace 'Shader$'),[Regex]::Escape($shaderName) -join '|' } ))" if ($SourceName) { Get-OBSInput | Where-Object InputName -eq $SourceName | Get-OBSSourceFilterList | Where-Object FilterName -Match $FilterNamePattern } else { $obs.Inputs | Get-OBSSourceFilterList | Where-Object FilterName -Match $FilterNamePattern } } 'Remove' { if ($SourceName) { Get-OBSInput | Where-Object InputName -eq $SourceName | Get-OBSSourceFilterList | Where-Object FilterName -Match $FilterNamePattern | Remove-OBSSourceFilter } } '(?>Add|Set)' { $ShaderSettings = [Ordered]@{} :nextParameter foreach ($parameterMetadata in $MyInvocation.MyCommand.Parameters[@($psBoundParameters.Keys)]) { foreach ($parameterAttribute in $parameterMetadata.Attributes) { if ($parameterAttribute -isnot [ComponentModel.DefaultBindingPropertyAttribute]) { continue } $ShaderSettings[$parameterAttribute.Name] = $PSBoundParameters[$parameterMetadata.Name] if ($ShaderSettings[$parameterAttribute.Name] -is [switch]) { $ShaderSettings[$parameterAttribute.Name] = $ShaderSettings[$parameterAttribute.Name] -as [bool] } continue nextParameter } } if (-not $PSBoundParameters['FilterName']) { $filterName = $PSBoundParameters['FilterName'] = $shaderName } $ShaderFilterSplat = [Ordered]@{ ShaderSetting = $ShaderSettings FilterName = $FilterName SourceName = $SourceName } foreach ($CarryOnParameter in "PassThru", "NoResponse","Force") { if ($PSBoundParameters.ContainsKey($CarryOnParameter)) { $ShaderFilterSplat[$CarryOnParameter] = $PSBoundParameters[$CarryOnParameter] } } if (-not $script:CachedShaderFilesFromCommand) { $script:CachedShaderFilesFromCommand = @{} } if ($Home -and -not $script:CachedShaderFilesFromCommand[$shaderName]) { $MyObsPowerShellPath = Join-Path $home ".obs-powershell" $ThisShaderPath = Join-Path $MyObsPowerShellPath "$shaderName.shader" $shaderText | Set-Content -LiteralPath $ThisShaderPath $script:CachedShaderFilesFromCommand[$shaderName] = Get-Item -LiteralPath $ThisShaderPath } if ($script:CachedShaderFilesFromCommand[$shaderName]) { $ShaderFilterSplat.ShaderFile = $script:CachedShaderFilesFromCommand[$shaderName].FullName } else { $ShaderFilterSplat.ShaderText = $shaderText } if ($myVerb -eq 'Add') { Add-OBSShaderFilter @ShaderFilterSplat } else { Set-OBSShaderFilter @ShaderFilterSplat } } } } } |