Hi @Hyllian, are you able to convert a (simple) glsl sharder to cg shader?
Snow pipeline shader exist in glsl format but not in cg format. If we convert it in cg format then we can add Snow pipeline shader (XBM menu).
pipeline_snow.glsl.frag.h:
Code:#include "shaders_common.h" static const char* stock_fragment_xmb_snow = GLSL( uniform float time; uniform vec2 OutputSize; float baseScale = 3.5; /* [1.0 .. 10.0] */ float density = 0.7; /* [0.01 .. 1.0] */ float speed = 0.25; /* [0.1 .. 1.0] */ float rand(vec2 co) { return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); } float dist_func(vec2 distv) { float dist = sqrt((distv.x * distv.x) + (distv.y * distv.y)) * (40.0 / baseScale); dist = clamp(dist, 0.0, 1.0); return cos(dist * (3.14159265358 * 0.5)) * 0.5; } float random_dots(vec2 co) { float part = 1.0 / 20.0; vec2 cd = floor(co / part); float p = rand(cd); if (p > 0.005 * (density * 40.0)) return 0.0; vec2 dpos = (vec2(fract(p * 2.0) , p) + vec2(2.0, 2.0)) * 0.25; vec2 cellpos = fract(co / part); vec2 distv = (cellpos - dpos); return dist_func(distv); } float snow(vec2 pos, float time, float scale) { /* add wobble */ pos.x += cos(pos.y * 1.2 + time * 3.14159 * 2.0 + 1.0 / scale) / (8.0 / scale) * 4.0; /* add gravity */ pos += time * scale * vec2(-0.5, 1.0) * 4.0; return random_dots(pos / scale) * (scale * 0.5 + 0.5); } void main(void) { float tim = time * 0.4 * speed; vec2 pos = gl_FragCoord.xy / OutputSize.xx; float a = 0.0; /** * Each of these is a layer of snow * Remove some for better performance * Changing the scale (3rd value) will mess with the looping **/ a += snow(pos, tim, 1.0); a += snow(pos, tim, 0.7); a += snow(pos, tim, 0.6); a += snow(pos, tim, 0.5); a += snow(pos, tim, 0.4); a += snow(pos, tim, 0.3); a += snow(pos, tim, 0.25); a += snow(pos, tim, 0.125); a = a * min(pos.y * 4.0, 1.0); gl_FragColor = vec4(1.0, 1.0, 1.0, a); } );
pipeline_snow.glsl.vert.h:
Code:#include "shaders_common.h" /* Need to duplicate these to work around broken stuff on Android. * Must enforce alpha = 1.0 or 32-bit games can potentially go black. */ static const char *stock_vertex_xmb_snow = GLSL( attribute vec2 TexCoord; attribute vec2 VertexCoord; attribute vec4 Color; uniform mat4 MVPMatrix; varying vec2 tex_coord; void main() { gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0); tex_coord = TexCoord; } );
I only know to port those shaders (inside shaders folder) outside RA inner code. I mean, I only know how to change the glsl or cg files thenselves, I know nothing about the RA inner shader spec code. I don't know what happens behind the scene.
I can give you some tips, though. The cg shaders combine vertex and fragment in only one file. I see that you have vert and frag separated in two files. I don't know if it's possible to separate cg.
Some tips to you, you should change these functions and special words when converting from glsl to cg:
Code:
Special words or functions:
glsl <--------> cg
fract --------> frac
mix --------> lerp
vec2 --------> float2
vec3 --------> float3
vec4 --------> float4
mat2 --------> float2x2
mat3 --------> float3x3
mat4 --------> float4x4
Thread related: https://forums.libretro.com/t/glsl-to-cg-conversion-cheat-sheet/437
There's a python script tool that does exactly the contrary of what you need:
https://github.com/Themaister/RetroArch/blob/master/tools/cg2glsl.py
Though it won't help directly, you should look at its code, because it can help you in your conversion.
Last edited:
