Thread Rating:
  • 10 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Shaders for GSdx
(12-11-2015, 10:13 PM)gregory Wrote: The requirement is openGL 3.3 + a couple of GL4 extensions. I'm far to request 4.3 (4.0 will already be a huge jump) (but I will love to do it Tongue).

Oh, I'm so sorry Gregory, that sentence must be a little confusing. I remember the OpenGL renderer being in the 3 something, but for ReShade, you need 4.3 to use the injector, which is a shame.

You've done great work on the renderer though, keep it up, it's been amazing to read up and see the progress happen. You're pretty amazing =).
Reply

Sponsored links

Looks like naoan cel-shading FX shader (based on MMJ's Cel Shader) got featured on YouTube recently, pretty cool!
https://www.youtube.com/watch?v=6c-t7Kj57dI

P.S. I'm assuming it's naoan's shader because it doesn't really look like Asmodean's.
[Image: pNm13X9.gif]
Windows 10 Pro x64 | Intel Core i7-4790K @ 4.00 GHz | PowerColor R9 290X 4GB | G.SKILL 16GB (4x4GB) DDR3 1600 RAM | Samsung 850 EVO 250 GB SSD | Seagate ST3000DM001 3TB HDD

CPU Intensive Games
GPU Intensive Games
Games that don't need a strong CPU
Reply
Posting this here in the hopes that the shading language-savvy people can help me. I'm trying to port the CRT shader made by Timothy Lottes to GSdx lingo.

What I have so far compiles but I get a black screen. sudonim said it's because it's failing to fetch pixels. I myself have no experience with shading languages so there is probably a gross mistake in what I have, so can someone take a look and correct what I have, please?


This is the source code in shadertoy: 
https://www.shadertoy.com/view/XsjSzR

This is what I have so far after comparing what's in libretro's crt-lottes.cg file and what's already in GSdx.fx:

Code:
/*------------------------------------------------------------------------------
                    [CRT LOTTES SECTION]
------------------------------------------------------------------------------*/

//
// PUBLIC DOMAIN CRT STYLED SCAN-LINE SHADER
//
//   by Timothy Lottes
//
// This is more along the style of a really good CGA arcade monitor.
// With RGB inputs instead of NTSC.
// The shadow mask example has the mask rotated 90 degrees for less chromatic aberration.
//
// Left it unoptimized to show the theory behind the algorithm.
//
// It is an example what I personally would want as a display option for pixel art games.
// Please take and use, change, or whatever.
//

// Hardness of scanline.
//  -8.0 = soft
// -16.0 = medium
float hardScan = -8.0;

// Hardness of pixels in scanline.
// -2.0 = soft
// -4.0 = hard
float hardPix = -3.0;

// Display warp.
// 0.0 = none
// 1.0/8.0 = extreme
float2 warp = float2(0.0, 0.0);

// Amount of shadow mask.
float maskDark = 0.5;
float maskLight = 1.5;

// sRGB to Linear.
// Assuing using sRGB typed textures this should not be needed.
//float ToLinear1(float c){
//    return (c <= 0.04045) ? c/12.92 : pow( abs((c+0.055)/1.055), 2.4);
//}

float3 ToLinear(float3 c) {
//    return float3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b));
   return RGBtoXYZ(c);
}

// Linear to sRGB.
// Assuing using sRGB typed textures this should not be needed.
//float ToSrgb1(float c){
//    return (c < 0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666)-0.055);
//}

float3 ToSrgb(float3 c) {
//    return float3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b));
   return XYZtoRGB(c);
}

// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
float3 Fetch(float2 pos, float2 off) {
   float2 res = screenSize.xy/6.0;

   pos = floor(pos*res+off)/res;
   if (max(abs(pos.x-0.5), abs(pos.y-0.5)) > 0.5) {
       return float3(0.0, 0.0, 0.0);
   }

   #if GLSL == 1
   return ToLinear( texture(TextureSampler, pos.xy).rgb );
   #else
   return ToLinear( sample_tex(TextureSampler, pos.xy).rgb );
   #endif
}

// Distance in emulated pixels to nearest texel.
float2 Dist(float2 pos) {
   float2 res = screenSize.xy/6.0;

   pos = pos*res.xy;
   return -((pos-floor(pos))-float2(0.5, 0.0));
}

// 1D Gaussian.
float Gaus(float pos, float scale) {
   return exp2(scale*pos*pos);
}

// 3-tap Gaussian filter along horz line.
float3 Horz3(float2 pos, float off) {
   float3 b = Fetch(pos, float2(-1.0, off));
   float3 c = Fetch(pos, float2( 0.0, off));
   float3 d = Fetch(pos, float2( 1.0, off));
   float dst = Dist(pos).x;
   // Convert distance to weight.
   float scale = hardPix;
   float wb = Gaus(dst-1.0, scale);
   float wc = Gaus(dst+0.0, scale);
   float wd = Gaus(dst+1.0, scale);
   // Return filtered sample.
   return (b*wb+c*wc+d*wd)/(wb+wc+wd);
}

// 5-tap Gaussian filter along horz line.
float3 Horz5(float2 pos, float off) {
   float3 a = Fetch(pos, float2(-2.0, off));
   float3 b = Fetch(pos, float2(-1.0, off));
   float3 c = Fetch(pos, float2( 0.0, off));
   float3 d = Fetch(pos, float2( 1.0, off));
   float3 e = Fetch(pos, float2( 2.0, off));
   float dst = Dist(pos).x;
   // Convert distance to weight.
   float scale = hardPix;
   float wa = Gaus(dst-2.0, scale);
   float wb = Gaus(dst-1.0, scale);
   float wc = Gaus(dst+0.0, scale);
   float wd = Gaus(dst+1.0, scale);
   float we = Gaus(dst+2.0, scale);
   // Return filtered sample.
   return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
}

// Return scanline weight.
float Scan(float2 pos, float off) {
   float dst = Dist(pos).y;
   return Gaus(dst+off, hardScan);
}

// Allow nearest three lines to effect pixel.
float3 Tri(float2 pos) {
   float3 a = Horz3(pos,-1.0);
   float3 b = Horz5(pos, 0.0);
   float3 c = Horz3(pos, 1.0);
   float wa = Scan(pos,-1.0);
   float wb = Scan(pos, 0.0);
   float wc = Scan(pos, 1.0);
   return a*wa+b*wb+c*wc;
}

// Distortion of scanlines, and end of screen alpha.
float2 Warp(float2 pos) {
   pos = pos*2.0-1.0;    
   pos *= float2(1.0+(pos.y*pos.y)*warp.x, 1.0+(pos.x*pos.x)*warp.y);
   return pos*0.5+0.5;
}

// Shadow mask.
float3 Mask(float2 pos) {
   pos.x += pos.y*3.0;
   float3 mask = float3(maskDark, maskDark, maskDark);
   pos.x = frac(pos.x / 6.0);
   if (pos.x < 0.333) {
       mask.r = maskLight;
   } else if (pos.x < 0.666) {
       mask.g = maskLight;
   } else {
       mask.b = maskLight;
   }

   return mask;
}    

// Entry
float4 CrtLottes( float4 fragColor, float2 fragCoord ) {
   float2 pos = Warp(fragCoord.xy/screenSize.xy);
   fragColor.rgb = Tri(pos)*Mask(fragCoord.xy);
   fragColor.a = 1.0;
   fragColor.rgb = ToSrgb(fragColor.rgb);

   return fragColor;
}


/*------------------------------------------------------------------------------
                    [MAIN() & COMBINE PASS CODE SECTION]
------------------------------------------------------------------------------*/

#if GLSL == 1
void ps_main()
#else
PS_OUTPUT ps_main(VS_OUTPUT input)
#endif
{
   #if GLSL == 1
   float2 texcoord = PSin.t;
   float4 position = PSin.p;
   float4 color = texture(TextureSampler, texcoord);
   #else
   PS_OUTPUT output;

   float2 texcoord = input.t;
   float4 position = input.p;
   float4 color = sample_tex(TextureSampler, texcoord);
   #endif

   // Here's where the shader is finally applied
   color = CrtLottes(color, texcoord);

   #if GLSL == 1
   SV_Target0 = color;
   #else
   output.c = color;

   return output;
   #endif
}
Reply
You need to declare input/output of the program. Check start of any glsl file.
Reply
(12-30-2015, 09:49 PM)gregory Wrote: You need to declare input/output of the program. Check start of any glsl file.

Hi gregory. I posted only the code section that's new plus the output section. The original one is basically this one
without all the other shader pass stuff.
I'll repeat that what I have compiles fine but I get a black screen.
Reply
The thing is that black screen is often due to a bad connection between shaders or a wrong uniform parameter.

Compile means nothings.

edit: or an output not between 0:1
First try to set a constant color, to check the connection.
Reply
Hello everybody and happy new year!

i need help about using external shader on pcsx2 1.2.1

I downloaded and pasted shader.fx and gsdx setting.ini in the root folder of pcsx2.
I checked the use of external shaders in plugin setting.

when i launch a game, i turn on the shaders with home button but when i press the f7 button to toggle between shaders, i only get the four native shaders!
how can i toggle these effects of external shaders?

thank you
Reply
Just google gsdx hotkeys. I have the feeling it is something like pageup/pagedown...
Reply
I don't know!
I'll try? It is not explained how can we toggle the new effects by the autor of the official guide. Just turn them on/off by home button.
Reply
I couldnt find it as well. Therefore probably you can not cycle through them.

Do you have several fx-files in your program dir that you would like to cycle through?
Reply




Users browsing this thread: 3 Guest(s)