Scripting Moderators ds1-e Posted November 19, 2018 Scripting Moderators Share Posted November 19, 2018 Hey. I have one big problem. Well i want to do something like, if we loss a lot of HP, then our screen will change colors, starting from minimal color changes, ends at this almost blackwhite screen. I wanna do similar thing as one MTA server have. Unfortunately i know nothing about using .fx files. So here i have 4 files, first it's script which use it, original blackwhite.fx and modified one and also grayscale.fx maybe it should help with something but i am not sure about it. local w, h = guiGetScreenSize(); isShaderBlackWhite = false function renderShader() dxSetRenderTarget(); dxUpdateScreenSource(screenSrc2); dxDrawImage(0,0,w,h,screenShader2); end function startRender() if screenShader2 == nil and screenSrc2 == nil then screenShader2 = dxCreateShader( "blackwhite.fx" ); screenSrc2 = dxCreateScreenSource( w, h ); if screenShader2 and screenSrc2 then dxSetShaderValue( screenShader2, "screenSource", screenSrc2 ); addEventHandler( "onClientHUDRender", getRootElement( ), renderShader ); end isShaderBlackWhite = true end end function stopRender() if screenShader2 and screenSrc2 then destroyElement( screenShader2 ); destroyElement( screenSrc2 ); screenShader2, screenSrc2 = nil, nil; removeEventHandler( "onClientHUDRender", getRootElement( ), renderShader ); isShaderBlackWhite = false end end function checkblood() if not getElementData(getLocalPlayer(), "blood") then return end if getElementData(getLocalPlayer(), "blood") <= 3631 then startRender() end if getElementData(getLocalPlayer(), "blood") >= 3632 then stopRender() end end setTimer(checkblood,2000,0) --addEventHandler("onClientPreRender",getRootElement(),getblood) // // blackwhite.fx // texture screenSource; sampler TextureSampler = sampler_state { Texture = <screenSource>; }; float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 { float4 color = tex2D(TextureSampler, TextureCoordinate); float value = (color.r + color.g + color.b) / 3; color.r = value; color.g = value; color.b = value; return color; } technique BlackAndWhite { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } texture BlackWhiteTexture; sampler screenSampler = sampler_state { Texture = <BlackWhiteTexture>; }; float4 main(float2 uv : TEXCOORD0) : COLOR0 { float4 Color; Color = tex2D( screenSampler , uv); Color.rgb = (Color.r+Color.g+Color.b)/3.0f; if (Color.r<0.2 || Color.r>0.9) Color.r = 0; else Color.r = 1.0f; if (Color.g<0.2 || Color.g>0.9) Color.g = 0; else Color.g = 1.0f; if (Color.b<0.2 || Color.b>0.9) Color.b = 0; else Color.b = 1.0f; return Color; }; technique BlackWhite { pass P1 { PixelShader = compile ps_2_0 main(); } } [/spoiler] float ColourAmount; Texture coloredTexture; sampler coloredTextureSampler = sampler_state { texture = <coloredTexture>; }; float4 GreyscalePixelShaderFunction(float2 textureCoordinate : TEXCOORD0) : COLOR0 { float4 color = tex2D(coloredTextureSampler, textureCoordinate); float3 colrgb = color.rgb; float greycolor = dot(colrgb, float3(0.3, 0.59, 0.11)); colrgb.rgb = lerp(dot(greycolor, float3(0.3, 0.59, 0.11)), colrgb, ColourAmount); return float4(colrgb.rgb, color.a); } technique Grayscale { pass GreyscalePass { PixelShader = compile ps_2_0 GreyscalePixelShaderFunction(); } } Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now