<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=WaRuS</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=WaRuS"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/WaRuS"/>
	<updated>2026-05-22T21:06:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=DxDrawBluredRectangle&amp;diff=71436</id>
		<title>DxDrawBluredRectangle</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=DxDrawBluredRectangle&amp;diff=71436"/>
		<updated>2021-07-04T09:20:48Z</updated>

		<summary type="html">&lt;p&gt;WaRuS: Created page with &amp;quot;{{Useful Function}} &amp;lt;lowercasetitle/&amp;gt; __NOTOC__ This function draws a 2D blured rectangle on the screen - rendered for one frame. This should be used in conjunction with onCli...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Useful Function}}&lt;br /&gt;
&amp;lt;lowercasetitle/&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function draws a 2D blured rectangle on the screen - rendered for one frame. This should be used in conjunction with onClientRender for continuous display.&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool dxDrawBluredRectangle ( float x, float y, float width, float height )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Required Arguments === &lt;br /&gt;
* '''x:''' An float representing the '''absolute''' origin X position of the rectangle, represented by pixels on the screen.&lt;br /&gt;
* '''y:''' An float representing the '''absolute''' origin Y position of the rectangle, represented by pixels on the screen.&lt;br /&gt;
* '''width:''' An float representing the width of the rectangle, drawn in a ''right'' direction from the origin.&lt;br /&gt;
* '''height:''' An float representing the height of the rectangle, drawn in a ''downwards'' direction from the origin.&lt;br /&gt;
&lt;br /&gt;
=== Required Files === &lt;br /&gt;
[https://cdn.discordapp.com/attachments/851000636484747274/861170045651910686/mta-helper.fx mta-helper.fx],&lt;br /&gt;
[https://cdn.discordapp.com/attachments/851000636484747274/861170042737393664/fxBlurV.fx fxBlurV.fx],&lt;br /&gt;
[https://cdn.discordapp.com/attachments/851000636484747274/861170040039669760/fxBlurH.fx fxBlurH.fx],&lt;br /&gt;
[https://cdn.discordapp.com/attachments/851000636484747274/861170037255307294/blurV.fx blurV.fx],&lt;br /&gt;
[https://cdn.discordapp.com/attachments/851000636484747274/861170034495455232/blurH.fx blurH.fx]&lt;br /&gt;
&lt;br /&gt;
=== Returns ===&lt;br /&gt;
Returns true if the operation was successful, false otherwise.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local scx, scy = guiGetScreenSize()&lt;br /&gt;
&lt;br /&gt;
Settings = {}&lt;br /&gt;
Settings.var = {}&lt;br /&gt;
Settings.var.blur = 1&lt;br /&gt;
Settings.var.optim = 4&lt;br /&gt;
Settings.screenRectangle = {}&lt;br /&gt;
&lt;br /&gt;
local current&lt;br /&gt;
&lt;br /&gt;
function createShader()&lt;br /&gt;
        myScreenSource = dxCreateScreenSource( scx/Settings.var.optim, scy/Settings.var.optim )&lt;br /&gt;
        blurHShader,tecName = dxCreateShader( &amp;quot;shaders/blurH.fx&amp;quot; )&lt;br /&gt;
        blurVShader,tecName = dxCreateShader( &amp;quot;shaders/blurV.fx&amp;quot; )&lt;br /&gt;
	bAllValid = myScreenSource and blurHShader and blurVShader&lt;br /&gt;
end&lt;br /&gt;
createShader()&lt;br /&gt;
&lt;br /&gt;
function blur_createBlurRenctagle(bool)&lt;br /&gt;
	if bool then&lt;br /&gt;
		Settings.screenRectangle = {pos_x, pos_y, size_x, size_y}&lt;br /&gt;
		createShader()&lt;br /&gt;
		addEventHandler( &amp;quot;onClientHUDRender&amp;quot;, root, blur_render2)&lt;br /&gt;
        else&lt;br /&gt;
		if isElement (blurHShader) and isElement (blurVShader) then&lt;br /&gt;
			Settings.screenRectangle = {}&lt;br /&gt;
			destroyElement (blurVShader)&lt;br /&gt;
			destroyElement (blurHShader)&lt;br /&gt;
		end&lt;br /&gt;
		removeEventHandler( &amp;quot;onClientHUDRender&amp;quot;, root, blur_render2)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function preRender ()&lt;br /&gt;
	if not Settings.var then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	RTPool.frameStart()&lt;br /&gt;
	dxUpdateScreenSource( myScreenSource )&lt;br /&gt;
	current = myScreenSource&lt;br /&gt;
	current = applyGBlurH( current, Settings.var.blur )&lt;br /&gt;
	current = applyGBlurV( current, Settings.var.blur )&lt;br /&gt;
	dxSetRenderTarget()&lt;br /&gt;
end&lt;br /&gt;
addEventHandler (&amp;quot;onClientRender&amp;quot;, root, preRender)&lt;br /&gt;
&lt;br /&gt;
function dxDrawBluredRectangle (pos_x, pos_y, size_x, size_y, color)&lt;br /&gt;
	 if bAllValid then&lt;br /&gt;
	 dxDrawImageSection  ( pos_x, pos_y, size_x, size_y, pos_x/Settings.var.optim, pos_y/Settings.var.optim, size_x/Settings.var.optim, size_y/Settings.var.optim, current, 0,0,0, color)&lt;br /&gt;
	 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function applyGBlurH( Src, blur )&lt;br /&gt;
	if not Src then return nil end&lt;br /&gt;
	local mx,my = dxGetMaterialSize( Src )&lt;br /&gt;
	local newRT = RTPool.GetUnused(mx,my)&lt;br /&gt;
	if not newRT then return nil end&lt;br /&gt;
	dxSetRenderTarget( newRT, true )&lt;br /&gt;
	dxSetShaderValue( blurHShader, &amp;quot;TEX0&amp;quot;, Src )&lt;br /&gt;
	dxSetShaderValue( blurHShader, &amp;quot;TEX0SIZE&amp;quot;, mx,my )&lt;br /&gt;
	dxSetShaderValue( blurHShader, &amp;quot;BLUR&amp;quot;, blur )&lt;br /&gt;
	dxDrawImage( 0, 0, mx, my, blurHShader )&lt;br /&gt;
	return newRT&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function applyGBlurV( Src, blur )&lt;br /&gt;
	if not Src then return nil end&lt;br /&gt;
	local mx,my = dxGetMaterialSize( Src )&lt;br /&gt;
	local newRT = RTPool.GetUnused(mx,my)&lt;br /&gt;
	if not newRT then return nil end&lt;br /&gt;
	dxSetRenderTarget( newRT, true )&lt;br /&gt;
	dxSetShaderValue( blurVShader, &amp;quot;TEX0&amp;quot;, Src )&lt;br /&gt;
	dxSetShaderValue( blurVShader, &amp;quot;TEX0SIZE&amp;quot;, mx,my )&lt;br /&gt;
	dxSetShaderValue( blurVShader, &amp;quot;BLUR&amp;quot;, blur )&lt;br /&gt;
	dxDrawImage( 0, 0, mx,my, blurVShader )&lt;br /&gt;
	return newRT&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
RTPool = {}&lt;br /&gt;
RTPool.list = {}&lt;br /&gt;
&lt;br /&gt;
function RTPool.frameStart()&lt;br /&gt;
	for rt,info in pairs(RTPool.list) do&lt;br /&gt;
		info.bInUse = false&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function RTPool.GetUnused( mx, my )&lt;br /&gt;
	for rt,info in pairs(RTPool.list) do&lt;br /&gt;
		if not info.bInUse and info.mx == mx and info.my == my then&lt;br /&gt;
			info.bInUse = true&lt;br /&gt;
			return rt&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local rt = dxCreateRenderTarget( mx, my )&lt;br /&gt;
	if rt then&lt;br /&gt;
		RTPool.list[rt] = { bInUse = true, mx = mx, my = my }&lt;br /&gt;
	end&lt;br /&gt;
	return rt&lt;br /&gt;
end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local scx, scy = guiGetScreenSize()&lt;br /&gt;
&lt;br /&gt;
function drawBluredRectangle()&lt;br /&gt;
	dxDrawBluredRectangle( scx/3.8, scy/3.8, scx/2.02, scy/2 )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
addEventHandler(&amp;quot;onClientRender&amp;quot;, root, drawBluredRectangle)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Author: fiXlly, WaRuS =====&lt;/div&gt;</summary>
		<author><name>WaRuS</name></author>
	</entry>
</feed>