CGP/GLSL

As we have lately worked on adding our shader manager to RGUI, and refactored a lot of the shader systems, the gap between XML/GLSL shaders and CGP is now complete with very little code. This format should be treated as a compatibility format for GLES platforms, and I don’t expect it to be used much.

Cg does not run on all platforms, i.e. when EGL context is used, and GLES. In these cases, only GLSL (ES) works, and to avoid a lot of mess in the shader manager later on, CGP now has a sister format, GLSLP, which is exactly the same as CGP, except that source files are GLSL.

Since the GLSL source files generally need to be split into two, #ifdefs need to be employed. By sticking both vertex and fragment into one, duplicating “varying” declarations is not needed. Note that only the “modern” GLSL style is supported in this format.

We still recommend that shaders are targeted against Cg, as it is much simpler to convert Cg -> GLSL (see cg2xml script) than the opposite direction. The original Cg spec is also more widely supported across platforms, APIs and different projects.

I will probably add functionality to convert .cg to .glsl as well in the near future.

E.g. stock.shader


<?xml version="1.0" encoding="UTF-8"?>
<shader language="GLSL" style="GLES2">
   <vertex><![CDATA[
      attribute vec2 TexCoord;
      attribute vec2 VertexCoord;
      uniform mat4 MVPMatrix;
      varying vec2 tex;
      void main()
      {
         gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0);
         tex = TexCoord;
      }
   ]]></vertex>
   <fragment><![CDATA[
      varying vec2 tex;
      uniform sampler2D Texture;
      void main()
      {
         gl_FragColor = texture2D(Texture, tex);
      }
   ]]></fragment>
</shader>

becomes

stock.glsl


      varying vec2 tex;
#if defined(VERTEX)
      attribute vec2 TexCoord;
      attribute vec2 VertexCoord;
      uniform mat4 MVPMatrix;

      void main()
      {
         gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0);
         tex = TexCoord;
      }
#elif defined(FRAGMENT)
      uniform sampler2D Texture;
      void main()
      {
         gl_FragColor = texture2D(Texture, tex);
      }
#endif

3 Likes

Tekst źródłowy 953 / 5000 Wyniki tłumaczenia I have a question do you know about slf and slv conversion?

I need a format

slangp

but i dont know how to do it the shader comes with the epsxe 2.0.5 emulator

full name is Cartoon I Class C slf, slv parameter is:

// Cartoon shader I (class C) // by guest ® // license: GNU-GPL

uniform sampler2D OGL2Texture;

void main () { vec3 uy = texture2D (OGL2Texture, gl_TexCoord [1] .xy) .xyz; vec3 lx = texture2D (OGL2Texture, gl_TexCoord [4] .xy) .xyz; vec3 ct = texture2D (OGL2Texture, gl_TexCoord [0] .xy) .xyz; vec3 rx = texture2D (OGL2Texture, gl_TexCoord [5] .xy) .xyz; vec3 dy = texture2D (OGL2Texture, gl_TexCoord [2] .xy) .xyz;

vec3 dt = vec3 (1.0,1.0,1.0);

float d = dot (abs (rx-lx), dt) + dot (abs (uy-dy), dt); d / = dot (ct, dt) + 0.15;

gl_FragColor.xyz = (1.1-pow (d, 1.5)) * ct;

I do not know how to do this .

I need this for

Beetle PSX HW Core Vulkan

it’s a great shader for epsxe but would be better on retroarch + vulkan

is it going to be converted to slangp format?