Jump to content

[QUESTION] Dx Render Target Rounded Corners


Recommended Posts

  • Ianec21 changed the title to [QUESTION] Dx Render Target Rounded Corners
-- Author: XaskeL
-- Created 06/05/2021
-- https://forum.mtasa.com/topic/130202-question-dx-render-target-rounded-corners/

local SHADER_CODE		= base64Decode( "AQn//gABAAAAAAAAAwAAAAEAAAAwAAAAAAAAAAAAAAAEAAAAAQAAAAAAgD8AAIA/AACAPwAAgD8GAAAAY29sb3IArAADAAAAAAAAAFwAAAAAAAAAAAAAAAEAAAABAAAAUrgePgcAAAByYWRpdXMAAAMAAAAAAAAAiAAAAAAAAAAAAAAAAQAAAAEAAAAK16M7CwAAAGJvcmRlclNvZnQAAAEAAAAAAAAAuAAAAAAAAAAAAAAAAQAAAAEAAAABAAAAEQAAAGNvbG9yT3ZlcndyaXR0ZW4AAAAAAQAAAA8AAAAEAAAAAAAAAAAAAAAAAAAAAwAAAFAwAAAMAAAAcm5kUmVjdFRlY2gABAAAAAEAAAACAAAAAgAAAAQAAAAgAAAAAAAAAAAAAAA8AAAAWAAAAAAAAAAAAAAAaAAAAIQAAAAAAAAAAAAAAJgAAAC0AAAAAAAAAAAAAADwAAAAAAAAAAEAAADoAAAAAAAAAAEAAACTAAAAAAAAANQAAADQAAAAAAAAAAEAAAAAAAAAAAAAAP////8AAAAAAAAAAGgHAAABAv///v9HAENUQUIcAAAA5wAAAAEC//8DAAAAHAAAAAAAACDgAAAAWAAAAAIABgABAAAAZAAAAHQAAACEAAAAAgAFAAEAAACMAAAAnAAAAKwAAAACAAcAAQAAAMAAAADQAAAAYm9yZGVyU29mdACrAAADAAEAAQABAAAAAAAAAArXozsAAAAAAAAAAAAAAABjb2xvcgCrqwEAAwABAAQAAQAAAAAAAAAAAIA/AACAPwAAgD8AAIA/Y29sb3JPdmVyd3JpdHRlbgCrq6sAAAEAAQABAAEAAAAAAAAAAACAPwAAAAAAAAAAAAAAAHBzXzJfYQBNaWNyb3NvZnQgKFIpIEhMU0wgU2hhZGVyIENvbXBp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AAAAAAAwAAoAIAAAAAAAAAAQAAAA4AAAAAAAAABwAAAAAAAAAAAAAABAAAABAAAADw8PDwDw8PD///AABRAAAFCAAPoAAAAD8AAAAAAACAPwAAAIAfAAACAAAAgAAAA7AfAAACAAAAgAAAD5BcAAACAAAIgAAAVbAGAAACAAABgAAA/4BbAAACAAACgAAAALAFAAADAAABgAAAAIAAAFWABgAAAgAAAYAAAACABQAAAwEAA4AAAACAAAAAsAUAAAMCAAOAAAAAgAgAAKABAAACAwAFgAgA5KAEAAAEAAADgAAAAIADAACAAAAAoQEAAAICAASACAAAoAEAAAIBAASAAABVsAIAAAMBAAeAAQDkgAIA5IEjAAACAQAHgAEA5IACAAADAAAIgAEAqoABAAChAgAAAwEACIAAAP+AAAAAoQIAAAMBAAiAAQD/gAYAAKAEAAAEAQAIgAEA/4ADAAChAwCqgAUAAAMBAAiAAQD/gAUA/6ACAAADAgABgAAA/4ECAACgWAAABAAACIAAAP+ACACqoQgAVaFYAAAEAQAIgAIAAIAFAP+gAQD/gAEAAAIAAASAAQAAoAIAAAMAAAeAAADkgQEA5IACAAADAQABgAAAAIAAAAChAgAAAwEAAYABAACABgAAoAQAAAQBAAGAAQAAgAMAAKEDAKqABQAAAwEAAYABAACABQD/oAIAAAMBAAKAAAAAgQIAAKBYAAAEAQABgAEAVYABAP+AAQAAgFoAAAQAAAKAAADpgAAA6YAIAFWgWAAABAAAAYAAAACAAAD/gAgA/6AHAAACAAACgAAAVYAGAAACAAACgAAAVYACAAADAAAEgAAAVYAAAAChAgAAAwAAAoAAAFWBAgAAoAIAAAMAAASAAACqgAYAAKAEAAAEAAAEgAAAqoADAAChAwCqgAUAAAMAAASAAACqgAUA/6BYAAAEAAACgAAAVYAFAP+gAACqgFgAAAQAABGAAAAAgAEAAIAAAFWABQAAAwAACIAAAACAAAD/kFgAAAQBAAeABwAAoQAA5JADAKqABQAAAwAAB4ABAOSABADkoAEAAAIACA+AAADkgP//AAA" );
local g_pShader 		= dxCreateShader( SHADER_CODE );
local _dxRenderTarget 	= dxDrawRectangle;
local _tocolor			= tocolor;

local function dxDrawRectangle( fPosX, fPosY, fWidth, fHeight, vColor, bPostDraw, bRound, fRadius, fBorderSoft )
	if ( not bRound ) then
		_dxRenderTarget( fPosX, fPosY, fWidth, fHeight, vColor, bPostDraw );
	else
		if ( type ( vColor ) == "table" ) then 
			dxSetShaderValue( g_pShader, "radius", fRadius );
			dxSetShaderValue( g_pShader, "borderSoft", fBorderSoft );
			dxSetShaderValue( g_pShader, "color", vColor );
			
			dxDrawImage( fPosX, fPosY, fWidth, fHeight, g_pShader, 0, 0, 0, -1, bPostDraw );
		end
	end
end

local function tocolor( iRed, iGreen, iBlue, iAlpha, bToShader )
	if ( not bToShader ) then
		return _tocolor( iRed, iGreen, iBlue, iAlpha );
	else
		return { iRed / 255, iGreen / 255, iBlue / 255, iAlpha / 255 };
	end
end;

local RED = tocolor( 255, 0, 0, 255, true );

addEventHandler( "onClientRender", root, function ( )
	dxDrawRectangle( 600, 600, 256, 256, RED, false, true, 0.2, 0.01 );
end );

I took the shader code from DGS and compiled it (for review, I hope thisdp won't mind). You don't have to drag around a huge number of files if you only need to draw the antialiased corners in dxDrawRectangle. Which you yourself can grab into the RenderTarget.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...