local Mask = {} --// Constructor Mask.Constructor = function (self) if self.Initialized then return self; end self.Shaders = {} self.CacheTextures = {} self.Shader = false; if not Draw or _G.Draw then _G.Draw = Require('Interface/Draw') _G.Draw:Constructor() end self.Initialized = true return self end --// Create Shader Mask.Create = function (self) if isElement(self.Shader) then return self.Shader end self.Shader = dxCreateShader(Mask:GetRaw()) if isElement(self.Shader) then -- outputDebugString('['..resource.name..']: [Mask] shader created successfully', 4, 255, 255, 255) return self.Shader end end Mask.Destroy = function (self) iprint('Destroying Mask shader and cache', self.Shader) if self.Shader then if isElement(self.Shader) then destroyElement(self.Shader) end self.Shader = nil end end --// Renew Shader Mask.Renew = function (self) if self.Shader then if isElement(self.Shader) then destroyElement(self.Shader) end self.Shader = nil end return self:Create() end --// Draw Mask.Draw = function (self, X, Y, Width, Height, Texture, MaskTexture, Rotation, RotationCenterOffsetX, RotationCenterOffsetY, Color, PostGUI, Rescale) if isElement(self.Shader) and isElement(MaskTexture) and isElement(Texture) then local _Width, _Height; local _ScaleX, _ScaleY local _PosX, _PosY; local Cache = self.CacheTextures[Texture] if not Cache then _Width, _Height = dxGetMaterialSize(Texture) if _Width and _Height then Cache = { Width = _Width or 64; Height = _Height or 64; } self.CacheTextures[Texture] = Cache addEventHandler('onClientElementDestroy', Texture, function() removeEventHandler('onClientElementDestroy', source, debug.getinfo(1).func) if Mask.CacheTextures[source] then Mask.CacheTextures[source] = nil end end) end end _Width = Cache.Width; _Height = Cache.Height; local _TextureAspect = (_Width / _Height) local _RenderAspect = (Width / Height) if (_TextureAspect > _RenderAspect) then _ScaleX = (_RenderAspect / _TextureAspect) _ScaleY = 1 _PosX = (1 - _ScaleX) / 2 _PosY = 0 else _ScaleX = 1 _ScaleY = (_TextureAspect / _RenderAspect) _PosX = 0 _PosY = (1 - _ScaleY) / 2 end if Rescale then dxSetShaderValue(self.Shader, 'gUVPosition', _PosX, _PosY) end dxSetShaderValue(self.Shader, 'gUVScale', _ScaleX, _ScaleY) dxSetShaderValue(self.Shader, 'sMaskTexture', MaskTexture) dxSetShaderValue(self.Shader, 'sPicTexture', Texture) return Draw:Image(X, Y, Width, Height, self.Shader, Rotation, RotationCenterOffsetX, RotationCenterOffsetY, Color, PostGUI) end end --// Get Raw Mask.GetRaw = function (self) return [[ texture sPicTexture; texture sMaskTexture; float2 gUVPrePosition = float2(0, 0); float2 gUVScale = float2(1, 1); // ESCALA DA TELA float2 gUVScaleCenter = float2(0.5, 0.5); // CENTRO DA ESCALA (NAO MEXER SE NAO FOR NECESSÁRIO) float gUVRotAngle = 0; // ROTACAO DA TEXTURA float2 gUVRotCenter = float2(0.5, 0.5); // CENTRO DA ROTACAO DA TESXTURA float2 gUVPosition = float2(0, 0); // POSICAO FINAL (DRAW SECTION) float3x3 computeTextureTransform() { float s = sin(gUVRotAngle); float c = cos(gUVRotAngle); float3x3 translationMatrix = float3x3( 1, 0, 0, 0, 1, 0, gUVPosition.x + gUVPrePosition.x, gUVPosition.y + gUVPrePosition.y, 1 ); float3x3 rotationMatrix = float3x3( c, s, 0, -s, c, 0, gUVRotCenter.x * (1 - c) + gUVRotCenter.y * s, gUVRotCenter.y * (1 - c) - gUVRotCenter.x * s, 1 ); float3x3 scaleMatrix = float3x3( gUVScale.x, 0, 0, 0, gUVScale.y, 0, gUVScaleCenter.x * (1 - gUVScale.x), gUVScaleCenter.y * (1 - gUVScale.y), 1 ); return mul(translationMatrix, mul(rotationMatrix, scaleMatrix)); } technique HudMaskTechnique { pass P0 { Texture[0] = sPicTexture; TextureTransform[0] = computeTextureTransform(); TextureTransformFlags[0] = Count2; AddressU[0] = Clamp; AddressV[0] = Clamp; ColorOp[0] = Modulate; ColorArg1[0] = Texture; ColorArg2[0] = Diffuse; AlphaOp[0] = Modulate; AlphaArg1[0] = Texture; AlphaArg2[0] = Diffuse; Texture[1] = sMaskTexture; TexCoordIndex[1] = 0; AddressU[1] = Clamp; AddressV[1] = Clamp; ColorOp[1] = SelectArg1; ColorArg1[1] = Current; AlphaOp[1] = Modulate; AlphaArg1[1] = Current; AlphaArg2[1] = Texture; ColorOp[2] = Disable; AlphaOp[2] = Disable; } } ]] end _G.Mask = Mask return Mask