Commands/Shaders/Get-OBSFilterTemplateShader.ps1
function Get-OBSFilterTemplateShader { [Alias('Set-OBSFilterTemplateShader','Add-OBSFilterTemplateShader')] param( # Set the ViewProj of OBSFilterTemplateShader [ComponentModel.DefaultBindingProperty('ViewProj')] [Single[][]] $ViewProj, # Set the image of OBSFilterTemplateShader [ComponentModel.DefaultBindingProperty('image')] [String] $Image, # Set the elapsed_time of OBSFilterTemplateShader [Alias('elapsed_time')] [ComponentModel.DefaultBindingProperty('elapsed_time')] [Single] $ElapsedTime, # Set the uv_offset of OBSFilterTemplateShader [Alias('uv_offset')] [ComponentModel.DefaultBindingProperty('uv_offset')] [Single[]] $UvOffset, # Set the uv_scale of OBSFilterTemplateShader [Alias('uv_scale')] [ComponentModel.DefaultBindingProperty('uv_scale')] [Single[]] $UvScale, # Set the uv_pixel_interval of OBSFilterTemplateShader [Alias('uv_pixel_interval')] [ComponentModel.DefaultBindingProperty('uv_pixel_interval')] [Single[]] $UvPixelInterval, # Set the uv_size of OBSFilterTemplateShader [Alias('uv_size')] [ComponentModel.DefaultBindingProperty('uv_size')] [Single[]] $UvSize, # Set the rand_f of OBSFilterTemplateShader [Alias('rand_f')] [ComponentModel.DefaultBindingProperty('rand_f')] [Single] $RandF, # Set the rand_instance_f of OBSFilterTemplateShader [Alias('rand_instance_f')] [ComponentModel.DefaultBindingProperty('rand_instance_f')] [Single] $RandInstanceF, # Set the rand_activation_f of OBSFilterTemplateShader [Alias('rand_activation_f')] [ComponentModel.DefaultBindingProperty('rand_activation_f')] [Single] $RandActivationF, # Set the loops of OBSFilterTemplateShader [ComponentModel.DefaultBindingProperty('loops')] [Int32] $Loops, # Set the local_time of OBSFilterTemplateShader [Alias('local_time')] [ComponentModel.DefaultBindingProperty('local_time')] [Single] $LocalTime, # Set the notes of OBSFilterTemplateShader [ComponentModel.DefaultBindingProperty('notes')] [String] $Notes, # 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 = 'filter_template' $ShaderNoun = 'OBSFilterTemplateShader' if (-not $psBoundParameters['ShaderText']) { $psBoundParameters['ShaderText'] = $ShaderText = ' //My shader modified by Me for use with obs-shaderfilter month/year v.02 //Section to converting GLSL to HLSL - can delete if unneeded #define vec2 float2 #define vec3 float3 #define vec4 float4 #define ivec2 int2 #define ivec3 int3 #define ivec4 int4 #define mat2 float2x2 #define mat3 float3x3 #define mat4 float4x4 #define fract frac #define mix lerp #define iTime float #define iTime elapsed_time #define iResolution float4(uv_size,uv_pixel_interval) /* **Shaders have these variables pre loaded by the plugin** **this section can be deleted** struct VertData { float4 pos : POSITION; float2 uv : TEXCOORD0; }; uniform float4x4 ViewProj; uniform texture2d image; uniform float elapsed_time; uniform float2 uv_offset; uniform float2 uv_scale; uniform float2 uv_pixel_interval; uniform float2 uv_size; uniform float rand_f; uniform float rand_instance_f; uniform float rand_activation_f; uniform int loops; uniform float local_time; */ uniform string notes< string widget_type = "info"; > = "add notes here"; float4 mainImage(VertData v_in) : TARGET { return image.Sample(textureSampler, v_in.uv); } /* **Shaders use the built in Draw technique** **this section can be deleted** technique Draw { pass { vertex_shader = mainTransform(v_in); pixel_shader = mainImage(v_in); } } */ ' } $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 } } } } } |