Dolphin, the GameCube and Wii emulator - Forums

Full Version: Possible to create a NTSC S-Video shader for Dolphin?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
So I have been playing around with the RetroArch Dolphin core at native resolution and slapped a NTSC S-Video shader on it and I liked the result very much!

Spoiler:
Would it be possible to create a shader with similar output for the standalone version of Dolphin?

The RetroArch Dolphin core is far far away from being close to stable at this point but when I tried it out with this shader I was hooked, I really like the authentic look.

EDIT: Seems like Dolphin is using .glsl shaders just like RetroArch but using the ones from RetroArch did nothing, just a black screen.
(08-22-2017, 10:42 PM)Maverick Hunter X Wrote: [ -> ]Would it be possible to create a shader with similar output for the standalone version of Dolphin?

Yes. It'd just take a fair amount of effort, but there shouldn't be anything inherently impossible about it, as far as I understand it.

(08-22-2017, 10:42 PM)Maverick Hunter X Wrote: [ -> ]EDIT: Seems like Dolphin is using .glsl shaders just like RetroArch but using the ones from RetroArch did nothing, just a black screen.

Generally, you really can't copy+paste shaders like that between two programs, not unless they know how their shaders are structured and what kind of input they need and output they give.
In fact, you can almost copy&paste such postprocessing shaders, as long as they use the same amount of features. eg Dolphin lacks all kind of geometry manipulation and multi-pass shaders (sadly) and we refuse to provide hacks to access the depth buffer. But for such a NTSC shader, I see no need for such features. It should be a simple texture in image out shader - as supported by dolphin.
Just pick a few as reference: https://github.com/dolphin-emu/dolphin/t...ys/Shaders
And port the retroarch shader to our syntax.
Looking at https://github.com/libretro/glsl-shaders...ideo.glslp which is the one I used for the RetroArch Dolphin core there is two .glsl shaders used, ntsc-pass1-svideo-2phase.glsl and ntsc-pass2-2phase-gamma.glsl

This is a stub taken from ntsc-pass1-svideo-2phase.glsl

Code:
#version 130

#define TWO_PHASE
#define SVIDEO

// begin params
#define PI 3.14159265

#if defined(TWO_PHASE)
    #define CHROMA_MOD_FREQ (4.0 * PI / 15.0)
#elif defined(THREE_PHASE)
    #define CHROMA_MOD_FREQ (PI / 3.0)
#endif

#if defined(COMPOSITE)
    #define SATURATION 1.0
    #define BRIGHTNESS 1.0
    #define ARTIFACTING 1.0
    #define FRINGING 1.0
#elif defined(SVIDEO)
    #define SATURATION 1.0
    #define BRIGHTNESS 1.0
    #define ARTIFACTING 0.0
    #define FRINGING 0.0
#endif
// end params

#if defined(VERTEX)

#if __VERSION__ >= 130
#define COMPAT_VARYING out
#define COMPAT_ATTRIBUTE in
#define COMPAT_TEXTURE texture
#else
#define COMPAT_VARYING varying
#define COMPAT_ATTRIBUTE attribute
#define COMPAT_TEXTURE texture2D
#endif

#ifdef GL_ES
#define COMPAT_PRECISION mediump
#else
#define COMPAT_PRECISION
#endif

COMPAT_ATTRIBUTE vec4 VertexCoord;
COMPAT_ATTRIBUTE vec4 COLOR;
COMPAT_ATTRIBUTE vec4 TexCoord;
COMPAT_VARYING vec4 COL0;
COMPAT_VARYING vec4 TEX0;
COMPAT_VARYING vec2 pix_no;

uniform mat4 MVPMatrix;
uniform COMPAT_PRECISION int FrameDirection;
uniform COMPAT_PRECISION int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;

// vertex compatibility #defines
#define vTexCoord TEX0.xy
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
#define outsize vec4(OutputSize, 1.0 / OutputSize)

void main()
{
    gl_Position = MVPMatrix * VertexCoord;
    COL0 = COLOR;
    TEX0.xy = TexCoord.xy;
   pix_no = vTexCoord * SourceSize.xy * (outsize.xy / InputSize.xy);
}

and this is a stub taken from Dolphins asciiart.glsl shader

Code:
const int char_width = 8;
const int char_height = 13;
const int char_count = 95;
const int char_pixels = char_width*char_height;
const float2 char_dim = float2(char_width, char_height);
const float2 font_scale = float2(1.0/float(char_width)/float(char_count), 1.0/float(char_height));

void main()
{
    float2 char_pos = floor(GetCoordinates()*GetResolution()/char_dim);
    float2 pixel_offset = floor(GetCoordinates()*GetResolution()) - char_pos*char_dim;

    // just a big number
    float mindiff = float(char_width*char_height) * 100.0;

    float minc = 0.0;
    float4 mina = float4(0.0, 0.0, 0.0, 0.0);
    float4 minb = float4(0.0, 0.0, 0.0, 0.0);

    for (int i=0; i<char_count; i++)
    {
        float4 ff = float4(0.0, 0.0, 0.0, 0.0);
        float4 f = float4(0.0, 0.0, 0.0, 0.0);
        float4 ft = float4(0.0, 0.0, 0.0, 0.0);
        float4 t = float4(0.0, 0.0, 0.0, 0.0);
        float4 tt = float4(0.0, 0.0, 0.0, 0.0);

        for (int x=0; x<char_width; x++)
        {
            for (int y=0; y<char_height; y++)
            {
                float2 tex_pos = char_pos*char_dim + float2(x,y) + 0.5;
                float4 tex = SampleLocation(tex_pos * GetInvResolution());

                float2 font_pos = float2(x+i*char_width, y) + 0.5;
                float4 font = SampleFontLocation(font_pos * font_scale);

                // generates sum of texture and font and their squares
                ff += font*font;
                f += font;
                ft += font*tex;
                t += tex;
                tt += tex*tex;
            }
        }

It differs quite a lot in terms of coding, well at least I think it does since I'm inexperienced.

How can I learn how to port RetroArch shaders to Dolphin in an easy way so it will work?

The only experience I have with shaders is combining and mixing different ones via the .glslp files but since Dolphin can't use multi-pass shaders that knowledge is pretty useless here.
(08-23-2017, 06:00 PM)degasus Wrote: [ -> ]In fact, you can almost copy&paste such postprocessing shaders, as long as they use the same amount of features.

I was mainly thinking uniforms would be an issue with some post-processing shaders. E.g. with GBE+ and its GLSL post-processing shaders, they require a small amount of specific uniforms passed in to function properly, even though most of the work is nothing more advanced than simple math and mix(). All most of my shaders need are the system's original screen size and the current emulator window size, but that's basic stuff. However, at least one relies on input from the current system clock (for colorizing B/W GB games according to time of day). Although, I'm no expert in GLSL, so maybe my shaders are weird outliers.
(08-24-2017, 12:40 AM)Shonumi Wrote: [ -> ]I was mainly thinking uniforms would be an issue with some post-processing shaders. E.g. with GBE+ and its GLSL post-processing shaders, they require a small amount of specific uniforms passed in to function properly, even though most of the work is nothing more advanced than simple math and mix(). All most of my shaders need are the system's original screen size and the current emulator window size, but that's basic stuff. However, at least one relies on input from the current system clock (for colorizing B/W GB games according to time of day). Although, I'm no expert in GLSL, so maybe my shaders are weird outliers.

That makes two of us not being experts in GLSL as I have been experimenting most of the day trying to get something to work or show up on the screen.
Looking at the shaders provided with Dolphin they look so simple and requires only a few lines of code to work.

Then looking at the shaders from RetroArch that's when I start to scratch my head big time, they're so complex I don't even know where to start.
Obviously I know nothing about writing shaders but making a nice NTSC S-Video shader seems like complete rocket science to me.

The games look so damn good with the NTSC S-Video shader that I can't stop thinking about it, it looks just like I remember it all those years back when I played GameCube games on the TV with S-Video connected.

I really don't care much for high resolution 4K experiences and I'm surprised that a shader like this never got made, I mean look at the screenshot, it looks so authentic.

Sure 1x resolution gets you half way there but you should really try out the RetroArch core with the ntsc-320px-svideo.glslp and see it in action.
It's so blurry it's hard to make out a lot of things. I don't remember my old TV being that bad....
However, I would like to see how this shader looks when applied to a game running a 3x or 4x IR.
(08-24-2017, 01:17 AM)KHg8m3r Wrote: [ -> ]It's so blurry it's hard to make out a lot of things. I don't remember my old TV being that bad....
However, I would like to see how this shader looks when applied to a game running a 3x or 4x IR.

I'll gladly provide you with more screenshots from other games, it looks totally fine here.

EDIT:

Here's a few more examples

Spoiler:
That looks worse than T.V. iirc Source: I have a trinitron in my room
(08-24-2017, 02:09 AM)JMC47 Wrote: [ -> ]That looks worse than T.V. iirc Source: I have a trinitron in my room
I'm so jealous right now. RGB cables I guess ?
Pages: 1 2