Scripting Moderators ds1-e Posted February 23, 2019 Scripting Moderators Share Posted February 23, 2019 Hey, as title says. How can i add possibility to change color intensity manual? To make it darker or brighter. // // 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(); } } Link to comment
AlexRazor Posted February 23, 2019 Share Posted February 23, 2019 Probably here: float value = (color.r + color.g + color.b) / 3; You should replace 3 with var and set this var value from your script. Link to comment
Discord Moderators Pirulax Posted February 23, 2019 Discord Moderators Share Posted February 23, 2019 // // blackwhite.fx // texture screenSource; float fIntesity; // the value set must be between in the range [-1, 1], so set it like this: urValue / 255, ex.: dxSetShaderValue(thisShader, "fIntesity", 128/255); this will make the image brighter. sampler TextureSampler = sampler_state { Texture = <screenSource>; }; float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 { float4 color = tex2D(TextureSampler, TextureCoordinate); return float4((color.r + color.g + color.b) / 3 + fIntesity); } technique BlackAndWhite { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } 1 Link to comment
Scripting Moderators ds1-e Posted February 24, 2019 Author Scripting Moderators Share Posted February 24, 2019 18 hours ago, Pirulax said: // // blackwhite.fx // texture screenSource; float fIntesity; // the value set must be between in the range [-1, 1], so set it like this: urValue / 255, ex.: dxSetShaderValue(thisShader, "fIntesity", 128/255); this will make the image brighter. sampler TextureSampler = sampler_state { Texture = <screenSource>; }; float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 { float4 color = tex2D(TextureSampler, TextureCoordinate); return float4((color.r + color.g + color.b) / 3 + fIntesity); } technique BlackAndWhite { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } local screenX, screenY = guiGetScreenSize() local screenSource = dxCreateScreenSource(screenX, screenY) addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() if getVersion ().sortable < "1.1.0" then outputChatBox("Resource is not compatible with this client.") return else blackWhiteShader, blackWhiteTec = dxCreateShader("fx/blackwhite.fx") if (not blackWhiteShader) then outputChatBox("Could not create shader. Please use debugscript 3.") else outputChatBox("shader " .. blackWhiteTec .. " was started.") end end end) addEventHandler("onClientPreRender", getRootElement(), function() if (blackWhiteShader) then dxUpdateScreenSource(screenSource) dxSetShaderValue(blackWhiteShader, "screenSource", screenSource) dxSetShaderValue(blackWhiteShader, "fIntesity", 128/255) dxDrawImage(0, 0, screenX, screenY, blackWhiteShader) end end) Thanks for answer, after doing changes, it shows an error. Link to comment
Discord Moderators Pirulax Posted February 24, 2019 Discord Moderators Share Posted February 24, 2019 That was helpful. What's the error? Link to comment
Scripting Moderators ds1-e Posted February 24, 2019 Author Scripting Moderators Share Posted February 24, 2019 (edited) Sorry, forget to add it to code, i did not slept today. [2019-02-24 11:01:00] WARNING: bw\blackwhite.lua:10: blackwhite.fx(16,12): error X3014: incorrect number of arguments to numeric-type constructor @ 'dxCreateShader' [fx/blackwhite.fx] Edited February 24, 2019 by majqq Link to comment
Scripting Moderators ds1-e Posted February 26, 2019 Author Scripting Moderators Share Posted February 26, 2019 bump Link to comment
TRtam Posted February 27, 2019 Share Posted February 27, 2019 (edited) Maybe this (Just change the intensity to whatever you want): // // blackwhite.fx // texture screenSource; float intensity = 0.5; 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 * intensity; color.r = value; color.g = value; color.b = value; return color; } technique BlackAndWhite { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } Or this: // // blackwhite.fx // texture screenSource; float intensity = 0; 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 * intensity; } technique BlackAndWhite { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } Edited February 27, 2019 by TRtam xd 1 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