Jump to content

dxSetShaderTransform Issue


Overkillz

Recommended Posts

Hello dear community. Today I've decided to recode my Radar script using some public shaders from resource like "Hud mask".

Well, the problem is that Im trying to use dxSetShaderTransform to flip the image and give it a negative increase value. 

But when I use this function, another shader that I've created is affected by this function.

For example: I want to apply dxSetShaderTransform only to speedShader, but, gtaMapShader is affected to.

Code

function drawRadar()
	--#EMPTY CIRCLE TEXTURE
	emptyCirclerTxt = dxCreateTexture("files/img/EmptyCircle_Thickness.png")

	--#GTA MAP PRE-REQUISITES
	gtaMapShader = dxCreateShader("files/shader/hud_mask.fx")
	gtaMapTexture = dxCreateTexture( "files/img/map.png")
	circleTxt = dxCreateTexture( "files/img/circle.png")
	if gtaMapShader and gtaMapTexture and circleTxt then
		dxSetShaderValue( gtaMapShader, "sPicTexture", gtaMapTexture )
		dxSetShaderValue( gtaMapShader, "sMaskTexture", circleTxt )
	end
	
	--#SPEEDOMETTER PRE-REQUISITES
	speedShader = dxCreateShader("files/shader/circle.fx")
	if emptyCirclerTxt then
		dxSetShaderValue(speedShader, "tex", emptyCirclerTxt)
		dxSetShaderTransform(speedShader,180,0,45)
	end
	
	addEventHandler("onClientRender",root,renderRadarContent)
end

function renderRadarContent()
	local px, py, pz = getElementPosition(lp)
	local pr = getPedRotation(lp)
	local cx, cy, _, tx, ty = getCameraMatrix()
	local north = findRotation(cx, cy, tx, ty)

	if gtaMapShader and gtaMapTexture and circleTxt then
		dxSetShaderValue( gtaMapShader, "gUVPosition", (px/6000),(py/-6000) )
		dxSetShaderValue( gtaMapShader, "gUVScale", (1/zoom), (1/zoom) )
		dxSetShaderValue( gtaMapShader, "gUVRotAngle", math.rad(-north) )
		dxSetShaderValue( gtaMapShader, "gUVRotAngle", math.rad(-north) )
		dxDrawImage(posX, posY, radarSize, radarSize, gtaMapShader, 0,0,0, tocolor(255,255,255,255) )
	end
	
	dxDrawImage(sX/2,sY/2, speedoSize, speedoSize, speedShader,45,0,0,tocolor(0,255,0,255))
	dxSetShaderValue(speedShader, "degree", (-1)*(1.5))
	dxSetShaderValue( speedShader, "rgba", 0/255, 0/255, 0/255,0.5)
	
end

I hope you can bring me a hand with this issue.

Thanks in advance, regards.

Link to comment
  • Moderators
3 hours ago, Overkillz said:

Does dxSetShaderTransform use or must use renderTargets ?

Nope, but shaders can hold other textures, and renderTargets can capture unexpected different parts of images. Combine those and it can cause exactly that problem. If there are no rendertargets in the rest of the code, then it is also a mystery for me. ?

Edited by IIYAMA
Link to comment

@IIYAMA

It is something weird. Here it is the current full code.

local sX,sY = guiGetScreenSize()
local radarSize = sY*0.2

local posX,posY = sX*0.02, sY*0.93-radarSize

local blipsize,lpsize,range = radarSize/22,radarSize/12,180
local centerleft,centertop = posX+radarSize/2,posY+radarSize/2
local lp = getLocalPlayer()

local scaleValue = sY / (1080)
scaleValue = math.max(scaleValue, 0.85) -- < IIYAMA's scale limit

local fontList = {
	[9] = dxCreateFont( "files/font/globalFont.ttf", 9*scaleValue ),
	[10] = dxCreateFont( "files/font/globalFont.ttf", 10*scaleValue ),
	[11] = dxCreateFont( "files/font/globalFont.ttf", 11*scaleValue ),
	[12] = dxCreateFont( "files/font/globalFont.ttf", 12*scaleValue ),
	[16] = dxCreateFont( "files/font/globalFont.ttf", 16*scaleValue ),
	[18] = dxCreateFont( "files/font/globalFont.ttf", 18*scaleValue ),
	[20] = dxCreateFont( "files/font/globalFont.ttf", 20*scaleValue ),
	[22] = dxCreateFont( "files/font/globalFont.ttf", 22*scaleValue ),
	[24] = dxCreateFont( "files/font/globalFont.ttf", 24*scaleValue )
}

local speedFontHeight = dxGetFontHeight(1,fontList[18])
local speedoSize = speedFontHeight*3


function drawRadar()
	--#EMPTY CIRCLE TEXTURE
	emptyCirclerTxt = dxCreateTexture("files/img/EmptyCircle_Thickness.png")

	--#GTA MAP PRE-REQUISITES
	gtaMapShader = dxCreateShader("files/shader/hud_mask.fx")
	gtaMapTexture = dxCreateTexture( "files/img/map.png")
	circleTxt = dxCreateTexture( "files/img/circle.png")
	if gtaMapShader and gtaMapTexture and circleTxt then
		outputDebugString("OK| creating the gtamap-prerequisites")
		dxSetShaderValue( gtaMapShader, "sPicTexture", gtaMapTexture )
		dxSetShaderValue( gtaMapShader, "sMaskTexture", circleTxt )
	end
	
	--#SPEEDOMETTER PRE-REQUISITES
	speedShader = dxCreateShader("files/shader/circle.fx")
	if emptyCirclerTxt then
		dxSetShaderValue(speedShader, "tex", emptyCirclerTxt)
		dxSetShaderTransform(speedShader,0,0,45)
	end
	
	addEventHandler("onClientRender",root,renderRadarContent)
end

function renderRadarContent()
	local px, py, pz = getElementPosition(lp)
	local pr = getPedRotation(lp)
	local cx, cy, _, tx, ty = getCameraMatrix()
	local north = findRotation(cx, cy, tx, ty)

	if gtaMapShader and gtaMapTexture and circleTxt then
		dxSetShaderValue( gtaMapShader, "gUVPosition", (px/6000),(py/-6000) )
		dxSetShaderValue( gtaMapShader, "gUVScale", (1/13), (1/13) )
		dxSetShaderValue( gtaMapShader, "gUVRotAngle", math.rad(-north) )
		dxSetShaderValue( gtaMapShader, "gUVRotAngle", math.rad(-north) )
		dxDrawImage(posX, posY, radarSize, radarSize, gtaMapShader, 0,0,0, tocolor(255,255,255,255) )
	end
	
	dxDrawImage(sX/2,sY/2, speedoSize, speedoSize, speedShader,45,0,0,tocolor(0,255,0,255))
	dxSetShaderValue(speedShader, "degree", (-1)*(1.5))
	dxSetShaderValue( speedShader, "rgba", 0/255, 0/255, 0/255,0.5)
	
end

function findRotation(x1, y1, x2, y2)
	local t = -math.deg(math.atan2(x2 - x1, y2 - y1))
	if t < 0 then
		t = t + 360
	end
	return t
end

drawRadar()

Look at the 64th line, The position should be near the bottom, but it is on the top due to dxSetShaderTransform.

Any idea why it could be caused. ? Im not a shader knowledger but might the matrix of the shader or something like that. But it is weird, Im using 2 DIFFERENT SHADERS.

Thanks and best regards.

Link to comment

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...