Jump to content

Change shader intensity


ds1-e

Recommended Posts

  • Scripting Moderators

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
  • Discord Moderators
//
// 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();
    }
}

 

  • Thanks 1
Link to comment
  • Scripting Moderators
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
  • Scripting Moderators

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 by majqq
Link to comment

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 by TRtam
xd
  • Thanks 1
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...