Skip to content

Commit

Permalink
Added the ability to scale/move for layer
Browse files Browse the repository at this point in the history
  • Loading branch information
cot6 committed Mar 21, 2019
1 parent a40a7bc commit fe08a85
Showing 1 changed file with 55 additions and 23 deletions.
78 changes: 55 additions & 23 deletions Shaders/Layer.fx
Expand Up @@ -2,7 +2,7 @@
| :: Description :: |
'-------------------/
Layer (version 0.1)
Layer (version 0.2)
Author: CeeJay.dk
License: MIT
Expand All @@ -14,50 +14,82 @@
Ideas for future improvement:
* More blend modes
* Texture size, placement and tiling control
* Tiling control
* A default Layer texture with something useful in it
History:
(*) Feature (+) Improvement (x) Bugfix (-) Information (!) Compatibility
Version 0.1
*
Version 0.2 by seri14 & Marot Satil
* Added the ability to scale and move the layer around on an x, y axis.
*/

#include "ReShade.fxh"

#if LAYER_SINGLECHANNEL //I plan to have some option to let users set this for performance sake.
#ifndef LAYER_SOURCE
#define LAYER_SOURCE "layer.png"
#endif
#ifndef LAYER_SIZE_X
#define LAYER_SIZE_X 1280
#endif
#ifndef LAYER_SIZE_Y
#define LAYER_SIZE_Y 720
#endif

#if LAYER_SINGLECHANNEL
#define TEXFORMAT R8
#else
#define TEXFORMAT RGBA8
#endif

#include "ReShadeUI.fxh"

//TODO blend by alpha
uniform float Layer_Blend < __UNIFORM_SLIDER_FLOAT1
uniform float2 Layer_Pos < __UNIFORM_DRAG_FLOAT2
ui_label = "Layer Position";
ui_min = 0.0; ui_max = 1.0;
ui_step = (1.0 / 200.0);
> = float2(0.5, 0.5);

uniform float Layer_Scale < __UNIFORM_DRAG_FLOAT1
ui_label = "Layer Scale";
ui_min = (1.0 / 100.0); ui_max = 4.0;
ui_step = (1.0 / 250.0);
> = 1.0;

uniform float Layer_Blend < __UNIFORM_COLOR_FLOAT1
ui_label = "Layer Blend";
ui_tooltip = "How much to blend layer with the original image.";
ui_min = 0.0;
ui_max = 1.0;
ui_step = 0.002;
ui_min = 0.0; ui_max = 1.0;
ui_step = (1.0 / 255.0); // for slider and drag
> = 1.0;

texture Layer_texture <source="Layer.png";> { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format=TEXFORMAT; };

sampler Layer_sampler { Texture = Layer_texture; };

float3 PS_Layer(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target {
float3 color = tex2D(ReShade::BackBuffer, texcoord).rgb;
float4 layer = tex2D(Layer_sampler, texcoord).rgba;

color = lerp(color, layer.rgb, layer.a * Layer_Blend);

return color;
//return layer.aaa;
texture Layer_Tex <
source = LAYER_SOURCE;
> {
Format = TEXFORMAT;
Width = LAYER_SIZE_X;
Height = LAYER_SIZE_Y;
};

sampler Layer_Sampler
{
Texture = Layer_Tex;
AddressU = BORDER;
AddressV = BORDER;
};

void PS_Layer(float4 pos : SV_Position, float2 texCoord : TEXCOORD, out float4 passColor : SV_Target)
{
const float4 backColor = tex2D(ReShade::BackBuffer, texCoord);
const float2 pixelSize = 1.0 / (float2(LAYER_SIZE_X, LAYER_SIZE_Y) * Layer_Scale / ReShade::ScreenSize);
const float4 layer = tex2D(Layer_Sampler, texCoord * pixelSize + Layer_Pos * (1.0 - pixelSize));

passColor = lerp(backColor, layer, layer.a * Layer_Blend);
passColor.a = backColor.a;
}

technique Layer {
technique Layer
{
pass
{
VertexShader = PostProcessVS;
Expand Down

0 comments on commit fe08a85

Please sign in to comment.