-
Posts
30 -
Joined
-
Last visited
Everything posted by marcelluss
-
Hello dear forum members, I am deeply interested in a persistent question regarding my shader for the effect of raindrops flowing down the sides of the car, as well as the effect of raindrops (spots) on the surface of the car (roof, bumper). I’ve been struggling with these issues for a long time and still can’t figure out how to solve my two problems. I hope someone can help me and explain to a beginner in HLSL how to properly implement the shader. The first problem is that I don’t understand how to make the raindrops flow down the different sides of the car. Essentially, I have a single texture applied to the car, and I can't figure out how to split it into multiple segments and adapt it to flow around the sides of the car. (I also need to account for the unique features of each car model so that the flow looks realistic on each vehicle.) The second problem is the effect of tiny raindrops on the roof, hood, and bumper of the car (the generation of small droplets that gradually appear and disappear). The issue is that I’m trying to apply both effects in one shader, but the problem is that either only one of them works under certain settings, or nothing works at all. I can't get both effects to work harmoniously together. I’ll also provide an example of the Lua script and the textures used for the shader. I really hope for your help. I've been spending too much time on this, and I can't seem to find a solution. float4x4 gWorld : WORLD; float4x4 gView : VIEW; float4x4 gProjection : PROJECTION; float gTime : TIME; // Rain parameters float gDropSpeed = 0.03; // Speed of droplet flow float2 noiseScale = float2(0.2, 0.8); // Noise texture scale float3 lightDirection = float3(1.0, 1.0, -1.0); // Light direction float gDropSpread = 0.3; // Droplet spread float gDropDepth = 0.3; // Droplet depth texture gTexture; // Main car texture texture texRain; // Raindrop texture texture texNormalRain; // Raindrop normals texture texNoise; // Noise texture // Variables for controlling the effect float gAlpha = 0.01; // Alpha channel for the car float rainAlpha = 1.8; // Alpha channel for raindrops sampler2D gTextureSampler = sampler_state { Texture = ( gTexture ); MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; sampler2D texRainSampler = sampler_state { Texture = ( texRain ); MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; sampler2D texNormalRainSampler = sampler_state { Texture = ( texNormalRain ); MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; sampler2D texNoiseSampler = sampler_state { Texture = ( texNoise ); MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; struct VertexShaderInput { float4 Position : POSITION; // Using standard POSITION semantics for the vertex shader float2 TextureCoordinate : TEXCOORD0; // Passing texture coordinates }; struct PixelShaderInput { float4 Position : POSITION; // Passing position as float4 for proper operation float3 WorldPos : TEXCOORD1; // Passing world coordinates for calculations float2 TextureCoordinate : TEXCOORD0; // Passing texture coordinates }; PixelShaderInput VertexShaderFunction(VertexShaderInput input) { PixelShaderInput output; // Position in world coordinates float4 worldPos = mul(input.Position, gWorld); // Storing position for further projection output.Position = mul(mul(input.Position, gWorld), gView); output.Position = mul(output.Position, gProjection); // Applying projection // Storing world coordinates (for droplet flow) output.WorldPos = worldPos.xyz; // Passing texture coordinates output.TextureCoordinate = input.TextureCoordinate; return output; } float4 PixelShaderFunction(PixelShaderInput output) : COLOR0 { float2 textureCoordinate = output.TextureCoordinate; // Main car texture float4 baseColor = tex2D(gTextureSampler, textureCoordinate); baseColor.rgb = max(baseColor.rgb, 0.1); // Brightening dark areas // Getting noise for random movement float noise = tex2D(texNoiseSampler, textureCoordinate * noiseScale).r; // World coordinates to determine droplet direction float3 worldPos = output.WorldPos; // Using world coordinates // Determining droplet direction based on normals and world position float3 normal = normalize(output.WorldPos); // Normal to the surface // Checking direction by normals to determine which side of the car we're on if (abs(normal.x) > abs(normal.y) && abs(normal.x) > abs(normal.z)) { // Side surfaces textureCoordinate.y += gDropSpeed * gTime; // Flowing down the sides } else if (normal.y > 0.5) { // Top surface (roof) textureCoordinate.y -= gDropSpeed * gTime; // Droplets flow down } else { // Other sides (front and back) textureCoordinate.x -= gDropSpeed * gTime; // Optionally add droplet flow forward/backward } // Reducing random offset for more precise flow float2 offset = gDropSpread * (noise * 4.0 - 0.5) * float2(1.0, 2.5); // Using float2 for offset textureCoordinate -= offset; // Applying deviation in both axes // Raindrop texture float4 rainColor = tex2D(texRainSampler, textureCoordinate); // Adjusting droplets to the car color rainColor.rgb = baseColor.rgb * 0.8 + float3(0.1, 0.1, 0.1); // Adding body tint to droplets rainColor.a = rainAlpha; // Alpha channel of droplets // Normals for droplets float4 tempRainNormal = tex2D(texNormalRainSampler, textureCoordinate); // Explicitly using float4 float3 rainNormal = normalize(tempRainNormal.rgb * 2.5 - 0.75); // Normalizing normals // Lighting on droplets float diffuse = saturate(dot(normalize(rainNormal), normalize(lightDirection))); // Correct lighting // Combining colors float4 finalColor = lerp(baseColor, rainColor, rainAlpha * diffuse); finalColor.a = lerp(gAlpha, rainAlpha, diffuse * 0.9); // Adding droplet depth finalColor.rgb += gDropDepth * 0.9; // Depth effect of droplets float3 v = float3(0.0, 0.0, 0.0); float Tr2 = gTime * 11000.0; float2 n = tex2D(texNoiseSampler, textureCoordinate * 0.5).rg; for (float r = 4.0; r > 0.0; r--) // Reducing the number of iterations { float2 x = 2100.0 * r * 0.015; float2 p = 6.28 * textureCoordinate * x + (n - 0.5) * 2.0; float4 d = tex2D(texNoiseSampler, round(textureCoordinate * x - 0.25) / x); float t = (sin(p.x) + sin(p.y)) * max(0.0, 1.0 - frac(Tr2 * (d.b + 0.1) + d.g) * 2.0); if (d.r < (2.0 - r) * 0.08 && t > 0.5) { v += normalize(float3(-cos(p.x), lerp(1.2, 2.0, t - 0.5), 0.0)); } } finalColor.rgb += v * rainAlpha; return finalColor; } technique Replace { pass P0 { DepthBias = -0.0001; AlphaBlendEnable = TRUE; SrcBlend = SRCALPHA; DestBlend = INVSRCALPHA; VertexShader = compile vs_1_1 VertexShaderFunction(); PixelShader = compile ps_3_0 PixelShaderFunction(); } } LUA CODE: local shader = dxCreateShader("fx/shader.fx", 2, 300, true, "vehicle"); local zapylyayushiesyaDetali = { "remap_body", }; local rainTexture = dxCreateTexture("assets/RainCar.png") local normalRainTexture = dxCreateTexture("assets/RainNormal.png") local noiseTexture = dxCreateTexture("assets/enbnoise.png") dxSetShaderValue(shader, "texRain", rainTexture) dxSetShaderValue(shader, "texNormalRain", normalRainTexture) dxSetShaderValue(shader, "texNoise", noiseTexture) -- Применение шейдера к машине local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then --engineApplyShaderToWorldTexture(shader, "vehiclegrunge256", vehicle) for _, name in ipairs(zapylyayushiesyaDetali) do engineRemoveShaderFromWorldTexture(shader, name, localPlayer.vehicle) engineApplyShaderToWorldTexture(shader, name, localPlayer.vehicle) end end renderTarget = dxCreateRenderTarget(512, 512, true) addEventHandler("onClientRender", root, function() iprint(shader) if shader then if renderTarget then dxSetRenderTarget(renderTarget, true) dxDrawImage(0, 0, 512, 512, shader) dxSetRenderTarget() dxDrawImage(50, 50, 256, 256, renderTarget) end end end)
-
- shader mta
- shader hlsl
-
(and 6 more)
Tagged with:
-
Hello guys, I want to implement an interesting feature in MTA for heating up the brake discs. I'm not sure where to start; how do you actually change the textures of specific car brake discs? Do I need a shader for this? If yes, what kind could serve as a base? Maybe there are already ready-made examples (systems)?
-
Hello, I would like to know if it is possible to somehow make a normal blur effect (glass) in mta? I know that there are shaders in the likeness of BlurBox, but they do not give enough blur and glass effect, is it possible to somehow achieve such an effect as in the screenshot below? Using a shader? I don't really know how to work with shaders if someone knows how to upgrade my shader, please help me please here is a variant of my shader code texture ScreenSource; float BlurStrength; float2 UVSize; sampler TextureSampler = sampler_state { Texture = <ScreenSource>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; static const float2 poisson[16] = { float2(-0.326212f, -0.40581f), float2(-0.840144f, -0.07358f), float2(-0.695914f, 0.457137f), float2(-0.203345f, 0.620716f), float2(0.96234f, -0.194983f), float2(0.473434f, -0.480026f), float2(0.519456f, 0.767022f), float2(0.185461f, -0.893124f), float2(0.507431f, 0.064425f), float2(0.89642f, 0.412458f), float2(-0.32194f, -0.932615f), float2(-0.65432f, -0.87421f), float2(-0.456899f, -0.633247f), float2(-0.123456f, -0.865433f), float2(-0.664332f, -0.25680f), float2(-0.791559f, -0.59771f) }; float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 { float4 color = tex2D(TextureSampler, TextureCoordinate); for(int i = 0; i < 14; i++) { float2 coord= TextureCoordinate.xy + (poisson[i] / UVSize * BlurStrength); color += tex2D(TextureSampler, coord); } return(color/17); } technique BlurShader { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } and here are two options for the result of my blurring the picture before and after applying the shader picture before picture after
-
thank you very much
-
I tried to use this function, but unfortunately I didn't quite understand how to use it :((( local rawSvgData = [[ <svg viewBox="0 0 600 600" xmlns="http://www.w3.org/2000/svg"> <defs> <linearGradient id="gradient"> <stop offset="5%" stop-color="#FF0000" /> <stop offset="95%" stop-color="#00FF00" /> </linearGradient> </defs> <path id="progress" fill="none" stroke="url(#gradient)" d="M300,50 A250,250,0,1,1,299.99,50" stroke-width="20" /> </svg> ]] local svgs = {} local function render(svg) if (not isElement(svg)) or (getElementType(svg) ~= "svg") then removeEventHandler("onClientRender", root, svgs[svg].handler) svgs[svg] = nil end local width, height = svgGetSize(svg) dxDrawImage(500, 500, 430, 430, svg, 0, 0, 0, tocolor(255, 255, 255), false) end local function onUpdate(svg) print("fe") if (not svgs[svg]) then svgs[svg] = { state = true, handler = function() render(svg) end } addEventHandler("onClientRender", root, svgs[svg].handler) end iprint("SVG texture updated", svg, getTickCount()) end addEventHandler("onClientResourceStart", root, function() mySvg = svgCreate(430, 430, rawSvgData, onUpdate) end) bindKey("l", "down", function() local newPath = updateState(100, 100, 300); addSVGRectNode(mySvg, path) end) function addSVGRectNode(svg, path) local svgXML = svgGetDocumentXML(svg) local rect = xmlCreateChild(svgXML, "rect") xmlNodeSetAttribute(rect, "d", path) local status = svgSetDocumentXML(svg, svgXML) print(status) end function updateState(value, total, R) local center local alpha = 360 / total * value local a = (90 - alpha) * math.pi / 180 local x = 300 + R * math.cos(a) local y = 300 - R * math.sin(a) local path if (total == value) then path = "M300,"..(300 - R).." A"..R..","..R..",0,1,1,299.99,"..(300 - R) else if (alpha > 180) then center = 1 else center = 0 end path = "M300,"..(300 - R).." A"..R..","..R..",0,"..center..",1,"..x..","..y end return path end The problem is that for some reason I can't change the source data of the svg file already (I tried to do as you said, well, for some reason it doesn't work) - besides, I didn't quite understand working with the arguments of this function, let's say I tried to manually call the function and replace the arguments the same as from the debug, but this it didn't work quite correctly, maybe I didn't quite understand the principle of these arguments of this function, what is responsible for what. Please help me
-
hello, I really liked your idea with the work of svg, is it possible to find out how to make the progress of reducing the strip in the svg code?
-
Hello, I ran into a problem with the dxDrawCircle function, I have a shader that allows you to apply a gradient to a texture, but the problem is that I need to make a gradient to a level system where there is a round strip with a gradient and I would like to attach a gradient there, but the problem is that dxDrawCircle does not accept a texture and I would like to somehow attach it there, or if possible, help me!
-
Hello, I would like to know if it is possible to make a countdown timer without using the SetTimer function? I wanted to do this in a more optimized and correct way because the usual SetTimer does not work quite in time. And I would like to make a dynamic function in which I can enter, say, 60 minutes into the arguments and a countdown timer will start with the output of minutes and seconds and at the same time use getRealTime. I tried to use many ways with this function, but they were all unsuccessful + I have already tried to find solutions on the forum and on the Internet, but all used SetTimer - unfortunately, it will not work to provide a ready-made code for my solution, because not one of them was even close to the solution I was moving towards
-
Hello, I've been trying to figure out for a very long time how to make a smooth 3d line? In terms of I know that there is a dxDrawLine3D, but this function allows you to create flat lines or to be more precise straight lines, and I need to make a smooth line in the likeness of drawing with a brush in the 3d world, but I can't figure out how to make such a smooth line, I wanted to make it for traces of players and cars
-
I want to find out how to implement the effect of the web on the screen. I've seen this on websites, in principle I have no idea how to do this, but just how optimized will it be? And is it even possible to implement it using a shader?
-
Problem with no collision (race version="0.8.3")
marcelluss replied to acp___(PL)'s topic in Scripting
create a colshape and track the contact of both colshapes -
The speed must be constantly set for this function to work. To do this, use a timer or a render to constantly maintain the speed. I don 't know for sure if it is possible to replace the shooting effect , but I can offer an option to create an object and count the trajectory of the bullet ( and already apply your shader to the object itself )
- 1 reply
-
- 1
-
local cursorShowing = false bindKey("f2", "down", function() cursorShowing = not cursorShowing showCursor(cursorShowing) end) local nameColor = white local nameSize = 1.2 local nameFont = "pricedown" local ped = createPed(0, 0, 0, 3); addEventHandler( "onClientRender", getRootElement(), function( ) --for _, plr in ipairs( getElementsByType( "player" ) ) do -- if not (plr == localPlayer) then local x, y, z = getPedBonePosition( ped, 8 ) local sX, sY = getScreenFromWorldPosition( x, y, z ) if sX then --local id = setElementData(plr, "id") local text if id then text ="Player ["..id.."]" else text = "Player" end local leftX = sX- dxGetTextWidth(text, nameSize, nameFont )/2 local topY = sY-60 local rightX = leftX local buttonY = topY dxDrawText( text, leftX, topY, rightX, buttonY, nameColor, nameSize, nameSize, nameFont, "left", "top", false, false, false, false, false) end -- end --end local w, h = guiGetScreenSize () local tx, ty, tz = getWorldFromScreenPosition ( w/2, h/2, 50 ) local px, py, pz = getCameraMatrix(localPlayer) -- test line -- local line = dxDrawLine3D(px, py, pz, x, y, z) local hit, x, y, z, elementHit = processLineOfSight ( px, py, pz, tx, ty, tz ) if hit then if elementHit then local sX, sY = getScreenFromWorldPosition( x, y, z ) dxDrawText("G", sX, sY, sX, sY, tocolor(255, 255, 255), 1, "default") end end end ) If I understood your idea correctly, then here is the script
-
can I see your full script?
-
it all depends on the animation itself, if the animation itself allows you to walk, then yes, you can walk with animation enabled, but this is not available to all animations. And also you can import your own animations into the game. The Internet is full of guides for creating animations for a character in the game.
-
use the following functions for this: dxDrawLine, getCameraMatrix
-
from personal experience, I do not advise you to use СEF - or to be more precise html interfaces (they are resource-intensive and very buggy since the browser version itself is also old to use). I talked to a lot of people on this topic and many of them claimed me and even gave many examples that this is really a senseless idea. + also, not everyone can load these interfaces
-
I apologize for my English, maybe I expressed myself incorrectly. I'm not trying to get the code from the client side to the server side or vice versa! the file from where I got the code and the code from the file from where I used it were both on the client side. But I have already fixed these errors, and to be more precise, somehow the error disappeared after restarting the server, but after that I ran into the problem of loading loadstring using the function, but I solved this problem as well. For some reason, when using the register_bridge function, I kept a path with a different resource name example [my resource was called shadow_fonts] - and it placed shadowfonts in the table. Well, again, I fixed that, too.
-
if you need a unique key, then why not generate it? For example, get the player's time and add a random value to it at the end? or the player element itself? And then hase it all in md5? md5(toJSON(getRealTime())..""..math.random(0, 5000)) else md5(toJSON(getRealTime())..""..localPlayer) -- client side else element player for server side
-
Hello, I made a system in the likeness of a bridge - the essence is to get functions and so on from one resource for use in another (I did this in order to use my libraries) - the problem is that there are two functions for registering a file and getting it ( using) I do this and debaging everything, the path she gets an example :shadow_fonts/client.lua - but when using this path, file Open gives an error that it cannot find the path to the file, I rechecked the correctness of the name 100 times when registering the file and the path to the folder, but not to which one. ShadowBridge = { ShadowBridgeData = {}; --[[void]] ShadowBridge = function(this) print("[ShadowBridge] Bridge constructor succesfull started!"); end, --[[bool]] Export = function(this, p_tree, src, path) local fullpath_to_file = (":"..p_tree.name.."/"..path); --print(fullpath_to_file); if not (fileExists(fullpath_to_file)) then return false; end this.ShadowBridgeData[src] = { --[[Resource]] parent = p_tree, --[[String]] src = src, --[[String]] full_path = fullpath_to_file, } print(inspect(this.ShadowBridgeData)) return true; end, --[[string]] Import = function(this, src) local file = fileOpen(this.ShadowBridgeData[src].full_path); print(this.ShadowBridgeData[src].full_path) local rawdata = fileRead(file, fileGetSize(file)); fileClose(file); return rawdata; end, } --[[Raw Code]] function GetBridge() return [[ function using(src_name) loadstring(exports.shadow_framework:Import(src_name))(); end function bridge_register(src_name, file_path) return exports.shadow_framework:Export(src_name, file_path) end ]] end --[[String]] function Import(src_name) return ShadowBridge:Import(src_name); end --[[Bool]] function Export(src_name, file_path) return ShadowBridge:Export(sourceResource, src_name, file_path); end example usage : imagine that I have a fonts client resource and a client.lua file -- client -- loadstring(exports.shadow_framework:GetBridge())(); bridge_register("fonts", "client.lua"); function test() print("hello world") end now the second example in another script, let's say main and the client.lua file - ( note that the client part is also where I want to use functions from another script ) -- client -- loadstring(exports.shadow_framework:GetBridge())(); using "fonts" but it gives the following errors https://imgur.com/a/TOYMa7k and yes, by the way, here are more places of the bridge resource <meta> <script src="framework_bridge.lua" type="shared" /> <export function="Import" type="server" /> <export function="Import" type="client" /> <export function="Export" type="server" /> <export function="Export" type="client" /> <export function="GetBridge" type="server" /> <export function="GetBridge" type="client" /> <oop>true</oop> </meta>
-
Hello, I have been tormented for a long time by a question related to blurring, namely on texture. I tried many methods to implement blur on a graphic element, but they all failed, and the fact is that in all shaders or resources, the player's screen is used for the blur texture and a shader is applied to it. And if you apply a blur to a transparent texture, then the blur will not work, and a black texture will be in the background in its place. After reading a lot of information on the implementation of blurring on different sources, I realized that blurring works in such a way that several images are taken that overlap each other and the transparency and position of the texture change and thus the blur effect is created, but here's the catch is it possible to implement this through a shader at all? Namely, to apply a blur to a transparent texture? Because I needed to create a 3d transparent image on which a blur will be superimposed and so that looking at the picture you can see the background behind it from the map well, this is more specific - below is an example of what exactly I wanted to implement. As you could see in the picture you can see a blurred box with glass effect blur, I need to do the same blur on a 3d element, but again, how can I apply a blur if the texture is transparent?
- 2 replies
-
- blur
- glasseffect
-
(and 1 more)
Tagged with:
-
Hello, I would like to know how you can apply a blur effect on a 3d picture in the world? I tried to use a shader from the blur_box resource, but for some reason it gives me a black texture if I apply a blur effect to a transparent image, and only allows you to apply a blur to a dxCreateScreenSource, and I would like to know how you can apply a blur effect to a 3d transparent image? And which shader is suitable for this?
-
you can determine the state of the player's life every time in the onClientRender render and make a check if the player has less than 1 hp, then constantly install 1 hp for him and set animation for him. this is a crutch option
-
make a check on the distance between two players and hide his nickname at a certain distance!
-
Hello again, I did this rotation animation a little differently and even added a 3d looking animation when the mouse is clamped, but there is only one problem that I can't fix for a long time... Namely, it is associated with rotation. The fact is that after turning the interpolation from 0 to -180 degrees and after that, when I hold down the key to view the plate, I have a mirror image on the other side, well, the problem is that in two versions of dxSetShaderTransform, I use different rotation. If possible, help me with an approximate solution, because I've tried many options and I can't figure out how to make it work better. here is an example video local screen = Vector2(guiGetScreenSize()); local px = ( screen.x / 1920 ); local size = Vector2(634*px, 376*px) local position = Vector2(screen.x / 2 - size.x / 2, screen.y / 2 - size.y / 2); local target = dxCreateRenderTarget( size.x, size.y, true ); local backTarget = dxCreateRenderTarget( size.x, size.y, true ); local stateRotation = false; local rotationX = 0; local tick = nil; local swithState = false; local stateRotationHover = true; function render() if isCursorShowing() then mx, my = getCursorPosition(); local rotX = (screen.x / 2) - mx * screen.x; local rotY = (screen.y / 2) - my * screen.y; if not stateRotation then if getKeyState("mouse1") then dxSetShaderTransform(maskShader, rotX / 100, -rotY / 100, 0 ) print(rotX) end else if tick then if not stateRotationHover then rotationX = interpolateBetween( 0, 0, 0, -180, 0, 0, ( getTickCount() - tick ) / 1000, "Linear" ) else rotationX = interpolateBetween( -180, 0, 0, 0, 0, 0, ( getTickCount() - tick ) / 1000, "Linear" ) end dxSetShaderTransform(maskShader, rotationX, 0, 0 ) end end end dxSetRenderTarget(target, true); if rotationX <= -90 then dxDrawImage(size.x, 0, -size.x, size.y, "assets/rect_box2.png", 0, 0, 0); else dxDrawImage(0, 0, size.x, size.y, "assets/rect_box.png", 0, 0, 0); end dxSetRenderTarget() dxDrawImage(position.x, position.y, size.x, size.y, maskShader); end addEventHandler("onClientClick", root, function(btn, state) if state == "down" then else return end; if isCursor(position.x, position.y, size.x, size.y) then if stateRotationHover then if not swithState then swithState = true; stateRotation = true; tick = getTickCount(); stateRotationHover = false; setTimer(function() swithState = false; stateRotation = false; end, 1000, 1) end elseif not stateRotationHover then if not swithState then swithState = true; stateRotation = true; tick = getTickCount(); stateRotationHover = true; setTimer(function() swithState = false; stateRotation = false; end, 1000, 1) end end end end) addEventHandler("onClientResourceStart", root, function() maskShader = dxCreateShader("assets/mask3d.fx"); maskTexture = dxCreateTexture("assets/rect_box.png"); dxSetShaderValue( maskShader, "sPicTexture", target ); dxSetShaderValue( maskShader, "sMaskTexture", maskTexture ); addEventHandler("onClientRender", root, render); showCursor(true); end) function isCursor(x, y, w, h) if not isCursorShowing() then return false end; local mx, my = getCursorPosition(); mx = mx * screen.x; my = my * screen.y; if ( mx >= x ) and ( mx <= x + w ) and ( my >= y ) and ( my <= y + h ) then return true end; end