namespace = TexFx

[ShaderRegexDiffuseTransparency]
shader_model = ps_4_0 ps_5_0
filter_index = 4243.05
temps = ini tex69 dim
run = CommandListResetResources
run = CommandListSetIntensity
if $costume_mods
    checktextureoverride = ps-t4
    checktextureoverride = ps-t5
    ; checktextureoverride = ps-t6
    ; checktextureoverride = ps-t7
    ; checktextureoverride = ps-t8
endif

;Cute regex to match (almost) every character diffuse shader and outline
[ShaderRegexDiffuseTransparency.Pattern]
(?P<MatchDiffuse>
dcl_output o0\.xyzw\n
dcl_output o1\.xyzw\n
dcl_output o2\.xyzw\n
dcl_output o3\.x\n
dcl_output o4\.x\n
dcl_output o5\.x\n
^[\s\S]+)
(?s)(?P<TillModesty>^discard_nz r0\.[xy]\nif_nz r0\.[xy]\n\s*lt.*?)
(?P<Modesty>discard\w+ \w+\.[xyzw]+\n)
(?P<TillRet>.*)
ret

[ShaderRegexDiffuseTransparency.InsertDeclarations]
dcl_resource_texture1d (float,float,float,float) t120
dcl_resource_texture2d (float,float,float,float) t69
dcl_sampler s15, mode_default

;Inserts a discard statement if any pixel from our ps-t69 texture is not OPAQUE
[ShaderRegexDiffuseTransparency.Pattern.Replace]
${MatchDiffuse}
ld_indexable(texture1d)(float,float,float,float) ${ini}.xyzw, l(69,0), t120.xyzw\n
${TillModesty}
\t	if_z ${ini}.z\n
\t\t	${Modesty}
\t	endif\n
;
${TillRet}
if_z ${ini}.y\n
\t	resinfo_indexable(texture2d)(float,float,float,float) ${dim}.xyyy, l(0), t69.xyzw\n
\t	if_nz ${dim}.xy\n
\t\t    ld_indexable(texture1d)(float,float,float,float) ${ini}.xyzw, l(70,0), t120.xyzw\n
\t\t	sample_indexable(texture2d)(float,float,float,float) ${tex69}.xyzw, v2.xy, t69.xyzw, s15\n
\t\t    mul ${tex69}.y, ${tex69}.y, ${ini}.y\n
\t\t    mul ${tex69}.z, ${tex69}.z, ${ini}.z\n
; Green Channel
\t\t	if_nz ${tex69}.y\n
\t\t\t		mov o1.w, ${tex69}.y\n
\t\t	endif\n
; Blue Channel
\t\t	if_nz ${tex69}.z\n
\t\t\t		mov o4.x, ${tex69}.z\n
\t\t	endif\n
; Red Channel
\t\t	discard_nz ${tex69}.x\n
\t	endif\n
endif\n
;debugging, remove diffuse
;discard_z l(0)\n
ret