CG to GLSL conversion failure

If you mean python 3, then yes…


xxx@xxx:~$ python3 --version
Python 3.2.3

And I got the script from one of your links somewhere, it had a preview form for testing glsl shaders on the web… the link took me to the repo, so i’m relatively sure I have the right version of the script, unless my spidey sense is way off. (Probably)…

Here’s a test of converting … scanline.cg


xxx@xxx:~$ ./cg2glsl.py ./shaders/scanline.cg ./xmlshaders/scanline.glsl
(67) : fatal error C9999: InitHAL failed

Vertex compilation failed ...

Another situation where I have absolutely no idea what’s going on, lol… Thanks again.

1 Like

I mean Cg version.

1 Like

Yup


cgc: version 3.0.0016, build date Feb 13 2011 17:29:46.

1 Like

Well, looks like you have to update. 3.0 probably doesn’t support GLES cross compile.

1 Like

How do I update? Apt tells me it’s newest version.


xxx@xxx:~$ sudo apt-get install nvidia-cg-toolkit
Reading package lists... Done
Building dependency tree       
Reading state information... Done
nvidia-cg-toolkit is already the newest version.
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

1 Like

You can try either downloading it directly from nvidia (http://developer.download.nvidia.com/cg/Cg_3.1/Cg-3.1_April2012_x86_64.deb) or install the raring package, which is 3.1.

1 Like

Alrighty, you guys are officially awesome!!! It converted scanline.cg to scanline.glsl and I copied it onto my RPi to test it and it worked perfectly.

Thanks alot guys.

1 Like

Glad to hear you got it worked out :slight_smile:

1 Like

I’m having a similar problem on Fedora:


$ retroarch-cg2glsl pixellate.cg pixellate.glsl
cgc: bad argument: ""
(0) : fatal error C9999: bad arguments


Vertex preprocessing failed ...
<stdin>(1) : error C0000: syntax error, unexpected ':', expecting "::" at token ":"

Vertex compilation failed ...


$ cgc -v
cgc: version 3.1.0013, build date Apr 24 2012 13:37:46.

Happens with every cg I’ve tried.

1 Like

@xenphor Have you tried using the Makefile.shaders script from the RetroArch source? If not, checkout the source from git, then from the main directory:

make -f Makefile.shaders checkout-shaders

then

make -f Makefile.shaders convert-xml

It will copy all of the converted shaders into media/shaders_glsl.

1 Like

Okay that worked well; although the one shader I wanted to use (pixellate) was not included it seems.

I mainly want to use a shader so I can have non-integer scaling without it looking bad. I guess it would be similar to mame with the prescale option set. I thought this is what the pixellate shader did so are there any others like that?

1 Like

Oh, that’s a shame. It should be very easy to convert by hand, though, since it just uses a passthrough vertex and the fragment part is pretty simple.

You can use this old XML/GLSL version for reference: https://gitorious.org/bsnes/xml-shaders … shader#L67

1 Like

It would be great if someone could hand convert it so that pixellate can be included in the android and ios ports.

1 Like

unfortunately I really have no idea about programming so I’ll just use what I can.

1 Like

See if this works for you:

// GLSL shader autogenerated by cg2glsl.py.
#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_VARYING     float _frame_rotation;
COMPAT_VARYING     vec4 _color1;
struct output_dummy {
    vec4 _color1;
};
struct input_dummy {
    vec2 _video_size;
    vec2 _texture_size;
    vec2 _output_dummy_size;
    float _frame_count;
    float _frame_direction;
    float _frame_rotation;
};
vec4 _oPosition1;
vec4 _r0005;
COMPAT_ATTRIBUTE vec4 VertexCoord;
COMPAT_ATTRIBUTE vec4 COLOR;
COMPAT_ATTRIBUTE vec4 TexCoord;
COMPAT_VARYING vec4 COL0;
COMPAT_VARYING vec4 TEX0;
 
uniform mat4 MVPMatrix;
uniform int FrameDirection;
uniform int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
void main()
{
    vec4 _oColor;
    vec2 _otexCoord;
    _r0005 = VertexCoord.x*MVPMatrix[0];
    _r0005 = _r0005 + VertexCoord.y*MVPMatrix[1];
    _r0005 = _r0005 + VertexCoord.z*MVPMatrix[2];
    _r0005 = _r0005 + VertexCoord.w*MVPMatrix[3];
    _oPosition1 = _r0005;
    _oColor = COLOR;
    _otexCoord = TexCoord.xy;
    gl_Position = _r0005;
    COL0 = COLOR;
    TEX0.xy = TexCoord.xy;
} 
#elif defined(FRAGMENT)

#if __VERSION__ >= 130
#define COMPAT_VARYING in
#define COMPAT_TEXTURE texture
out vec4 FragColor;
#else
#define COMPAT_VARYING varying
#define FragColor gl_FragColor
#define COMPAT_TEXTURE texture2D
#endif

#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#define COMPAT_PRECISION mediump
#else
#define COMPAT_PRECISION
#endif
COMPAT_VARYING     float _frame_rotation;
COMPAT_VARYING     vec4 _color;
struct output_dummy {
    vec4 _color;
};
struct input_dummy {
    vec2 _video_size;
    vec2 _texture_size;
    vec2 _output_dummy_size;
    float _frame_count;
    float _frame_direction;
    float _frame_rotation;
};
uniform sampler2D Texture;
COMPAT_VARYING vec4 TEX0;
COMPAT_VARYING vec2 texCoord;
 
uniform int FrameDirection;
uniform int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
void main()
{
vec2 texelSize = 1.0 / TextureSize;

                vec2 range = vec2(abs(dFdx(TEX0.x)), abs(dFdy(TEX0.y)));
                range = range / 2.0 * 0.999;

                float left   = TEX0.x - range.x;
                float top    = TEX0.y + range.y;
                float right  = TEX0.x + range.x;
                float bottom = TEX0.y - range.y;

                vec4 topLeftColor     = texture(Texture, vec2(left, top));
                vec4 bottomRightColor = texture(Texture, vec2(right, bottom));
                vec4 bottomLeftColor  = texture(Texture, vec2(left, bottom));
                vec4 topRightColor    = texture(Texture, vec2(right, top));

                vec2 border = clamp(
                        round(TEX0.xy / texelSize) * texelSize,
                        vec2(left, bottom),
                        vec2(right, top)
                    );

                float totalArea = 4.0 * range.x * range.y;

                vec4 averageColor;
                averageColor  = ((border.x - left)  * (top - border.y)    / totalArea) * topLeftColor;
                averageColor += ((right - border.x) * (border.y - bottom) / totalArea) * bottomRightColor;
                averageColor += ((border.x - left)  * (border.y - bottom) / totalArea) * bottomLeftColor;
                averageColor += ((right - border.x) * (top - border.y)    / totalArea) * topRightColor;
    FragColor = averageColor;
    return;
} 
#endif
1 Like

Hm didn’t work


RetroArch [ERROR] :: Failed to compile fragment shader #0
RetroArch [ERROR] :: Failed to create GL program #0.
RetroArch [WARN] :: [GL]: Failed to set multipass shader. Falling back to stock.
RetroArch [WARN] :: [GL]: Stock GLSL shaders will be used.
RetroArch [ERROR] :: Setting RGUI CGP failed.

1 Like

Ok, it compiles for me on an AMD GPU but I’ll try it on some others and see what’s killing it.

1 Like

there also seems to be an issue with my latest mdapt shader and this conversion script, maybe you can take a look into it? I’ll gladly modify mdapt if there is an issue so that it works again with cg2gsl. here is the post describing the problem:

viewtopic.php?f=6&t=493&start=125#p9485

1 Like

I probably should’ve posted the error output of my conversions


9 shaders failed.
Failed shaders:
media/shaders/pixellate.cg
media/shaders/handheld/lcd-shader/backup/lcd-pass-0.cg
media/shaders/handheld/lcd-shader/backup/lcd-pass-1.cg
media/shaders/handheld/lcd_cgwg/lcd-grid.cg
media/shaders/ntsc/ntsc-pass2-vertex.cg
media/shaders/ntsc/ntsc-pass2-demodulate.cg
media/shaders/ntsc/ntsc-pass1-vertex.cg
media/shaders/ntsc/ntsc-pass1-encode.cg
media/shaders/ntsc/ntsc-pass3-vertex.cg

That’s on Fedora 19 64bit.

1 Like

17 posts were merged into an existing topic: CRT Squabblin’