mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-26 01:11:32 +11:00
Merge pull request #37 from Monroe88/patch-4
Add parameters to sharp-bilinear and AANN shaders
This commit is contained in:
commit
e7513579ad
|
@ -1,5 +1,12 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
float NOGAMMA;
|
||||
float MASKING;
|
||||
float BILINEAR;
|
||||
} param;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
|
@ -13,14 +20,14 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
|||
// Licensed MIT
|
||||
|
||||
// set to true to interpolate in sRGB instead of a pseudo-perceptual colorspace
|
||||
#define NOGAMMA false
|
||||
#pragma parameter NOGAMMA "Interpolate in sRGB" 0.0 0.0 1.0 1.0
|
||||
|
||||
// set to true to compensate for 8px overscan masking
|
||||
// Note: overscan compensation slightly alters (extremifies) the pixel aspect ratio of the game if said pixel aspect ratio is not exactly 1:1
|
||||
#define MASKING false
|
||||
#pragma parameter MASKING "8px Overscan Masking" 0.0 0.0 1.0 1.0
|
||||
|
||||
// Do bilinear filtering instead of anti-aliased nearest neighbor filtering (used for debugging color)
|
||||
#define BILINEAR false
|
||||
#pragma parameter BILINEAR "Force Bilinear Filtering" 0.0 0.0 1.0 1.0
|
||||
|
||||
// http://i.imgur.com/kzwZkVf.png
|
||||
|
||||
|
@ -69,7 +76,7 @@ vec3 linear2srgb(vec3 linear) {
|
|||
#define BS 0.0722
|
||||
|
||||
vec3 rgb2vry(vec3 rgb) {
|
||||
if (NOGAMMA)
|
||||
if (param.NOGAMMA == 1.0)
|
||||
return rgb;
|
||||
|
||||
// https://en.wikipedia.org/wiki/Opponent_process
|
||||
|
@ -87,7 +94,7 @@ vec3 rgb2vry(vec3 rgb) {
|
|||
return vry;
|
||||
}
|
||||
vec3 vry2rgb(vec3 vry) {
|
||||
if (NOGAMMA)
|
||||
if (param.NOGAMMA == 1.0)
|
||||
return vry;
|
||||
|
||||
// Magic.
|
||||
|
@ -103,7 +110,7 @@ vec3 vry2rgb(vec3 vry) {
|
|||
}
|
||||
|
||||
vec3 vry_interp(vec3 first, vec3 second, float frac) {
|
||||
if (NOGAMMA)
|
||||
if (param.NOGAMMA == 1.0)
|
||||
return first*NOT(frac) + second*YES(frac);
|
||||
|
||||
// Because the chroma values were generated on linear light, but the luma must be interpolated in perceptual gamma (3)
|
||||
|
@ -124,7 +131,7 @@ vec3 vry_interp(vec3 first, vec3 second, float frac) {
|
|||
}
|
||||
|
||||
vec3 percent(float ssize, float tsize, float coord) {
|
||||
if (BILINEAR)
|
||||
if (param.BILINEAR == 1.0)
|
||||
tsize = ssize;
|
||||
|
||||
float minfull = (coord*tsize - 0.5)/tsize*ssize;
|
||||
|
@ -146,7 +153,7 @@ vec3 percent(float ssize, float tsize, float coord) {
|
|||
void main() {
|
||||
vec2 viewportSize = global.OutputSize.xy;
|
||||
vec2 gameCoord = vTexCoord;
|
||||
if (MASKING) {
|
||||
if (param.MASKING == 1.0) {
|
||||
float hscale = viewportSize.x/global.SourceSize.x;
|
||||
float vscale = viewportSize.y/global.SourceSize.y;
|
||||
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#version 450
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
float SHARP_BILINEAR_PRE_SCALE;
|
||||
} param;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
|
@ -9,7 +14,7 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
|||
} global;
|
||||
|
||||
/*
|
||||
* sharp-bilinear.cg
|
||||
* sharp-bilinear.slang
|
||||
* Author: Themaister
|
||||
* License: Public domain
|
||||
*
|
||||
|
@ -17,7 +22,7 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
|||
* sharper image than plain bilinear.
|
||||
*/
|
||||
|
||||
#define SHARP_BILINEAR_PRE_SCALE 4.0
|
||||
#pragma parameter SHARP_BILINEAR_PRE_SCALE "Sharp Bilinear Prescale" 4.0 1.0 10.0 1.0
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
|
@ -40,13 +45,13 @@ void main()
|
|||
vec2 texel = vTexCoord * global.SourceSize.xy;
|
||||
vec2 texel_floored = floor(texel);
|
||||
vec2 s = fract(texel);
|
||||
float region_range = 0.5 - 0.5 / SHARP_BILINEAR_PRE_SCALE;
|
||||
float region_range = 0.5 - 0.5 / param.SHARP_BILINEAR_PRE_SCALE;
|
||||
|
||||
// Figure out where in the texel to sample to get correct pre-scaled bilinear.
|
||||
// Uses the hardware bilinear interpolator to avoid having to sample 4 times manually.
|
||||
|
||||
vec2 center_dist = s - 0.5;
|
||||
vec2 f = (center_dist - clamp(center_dist, -region_range, region_range)) * SHARP_BILINEAR_PRE_SCALE + 0.5;
|
||||
vec2 f = (center_dist - clamp(center_dist, -region_range, region_range)) * param.SHARP_BILINEAR_PRE_SCALE + 0.5;
|
||||
|
||||
vec2 mod_texel = texel_floored + f;
|
||||
|
||||
|
|
Loading…
Reference in a new issue