• Stars
    star
    1,011
  • Rank 45,471 (Top 0.9 %)
  • Language
    C
  • Created almost 13 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Collection of commonly used Cg shaders. These shaders are usable by either HLSL and/or Cg runtime compilers. The cg2glsl script will translate most of these into GLSL shaders.
================================
 -- Common shaders --
================================

This is a package of pixel shaders intended for old school emulators. 
Copyrights are held by the respective authors.
The shaders are coded in the Cg language, suitable for both OpenGL and D3D.
Most of these shaders are converted from other languages (GLSL, FX, HLSL, etc).

The shaders all follow a convention which must be followed by the implementer 
of an OGL/D3D backend.

Known implementations of this spec are currently:
- RetroArch
- SNES9x (Win32 port)
- OpenEmu

Entry points:
   Vertex: main_vertex
   Fragment: main_fragment

Texture unit:
   All shaders work on texture unit 0 (the default). 2D textures must be used.
   Power-of-two sized textures are recommended for optimal visual quality.
   The shaders must deal with the actual picture data not 
   filling out the entire texture.
   Incoming texture coordinates and uniforms provide this information.

   The texture coordinate origin is defined to be top-left oriented, i.e.
   a texture coordinate of (0, 0) will always refer to the top-left pixel of
   the visible frame. This is opposite of what most graphical APIs expect.
   The implementation must always ensure that this ordering is held for any
   texture that the shader has access to.

   Every texture bound for a shader must have black border mode set.
   I.e. sampling a texel outside the given texture coordinates must always return a pixel
   with RGBA values (0, 0, 0, 0).

Uniforms:
   Some parameters will need to be passed to all shaders, 
   both vertex and fragment program.
   A generic entry point for fragment shader will look like:

   float4 main_fragment (float2 tex : TEXCOORD0, 
      uniform input IN, uniform sampler2D s_p : TEXUNIT0) : COLOR
   {}

   The input is a struct looking like:
   struct input
   {
      float2 video_size;
      float2 texture_size;
      float2 output_size;
      float frame_count;
      float frame_direction;
   };

   TEXCOORD0: Texture coordinates for the current input frame will be passed in TEXCOORD0.
   (TEXCOORD is a valid alias for TEXCOORD0).

   COLOR0: Although legal, no data of interest is passed here.
   You cannot assume anything about data in this stream.

   IN.video_size: The size of the actual video data in the texture, 
   e.g for a SNES this will be generally 
   (256, 224) for normal resolution frames.

   IN.texture_size: This is the size of the texture itself. 
   Optimally power-of-two sized.

   IN.output_size: The size of the video output. 
   This is the size of the viewport shown on screen.

   IN.frame_count: A counter of the frame number. 
   This increases with 1 every frame. 
   This value is really an integer, 
   but needs to be float for CGs lack of integer uniforms.

   IN.frame_direction: A number telling which direction
   the frames are flowing. For regular playing, this value should be 1.0.
   While the game is rewinding, this value should be -1.0.

   modelViewProj: This uniform needs to be set in vertex shader. 
   It is a uniform for the current MVP transform.

Pre-filtering:
   Most of these shaders are intended to be used with a non-filtered input. 
   Nearest-neighbor filtering on the textures themselves are preferred.
   Some shaders, like scanline will most likely 
   prefer bilinear texture filtering.


Genres:
   There are several different types of shaders available, 
   some of the relevant types are sorted into folders.

   2x-classic:
      These are the typical, classic filters usually run on CPU, such as 
      HQ2x, 2xSaI, SuperEagle, etc, converted into shaders.

   Blur:
      Shaders focusing on bluring the output image.

   Enhance:
      Shaders focusing on enhancing the image quality 
      through other means than bluring only. 

   TV:
      Shaders focusing on replicating the visual image of a 
      game running on a CRT screen.

   Misc:
      Shaders that do not directly fit into any of the above categories.

   Meta:
      Contains meta-shaders *.cgp.


=============================
 -- Cg meta-shader format --
=============================

Rationale:
The .cg files themselves contain no metadata necessary to perform advanced
filtering. They also cannot process an effect in multiple passes, which
is necessary for some effects. The CgFX format does exist, but it would
need current shaders to be rewritten to a HLSL-esque format.
It also suffers a problem mentioned below.

Rather than putting everything into one file (XML shader format), this
format is config file based. This greatly helps testing shader combinations
as there is no need to rearrange code in one big file. Another plus with
this approach is that a large library of .cg files can be used to combine
many shaders without needing to redundantly copy code over. It also
helps testing as it is possible to unit-test every pass separately 
completely seamless.


Format:

The meta-shader format is based around the idea of a config file with the
format: key = value. Values with spaces need to be wrapped in quotes:
key = "value stuff". No .ini sections or similar are allowed. Meta-shaders
may include comments, prefixed by the "#" character, both on their own in
an otherwise empty line or at the end of a key = value pair.

The meta-format has four purposes:
-  Combine several standalone .cg shaders into a multipass shader.
-  Define scaling parameters for each pass. I.e., a HQ2x shader
   might want to output with a scale of exactly 2x.
-  Control filtering of textures. Many shaders will want nearest-neighbor
   filtering, and some will want linear.
-  Define external lookup textures. Shaders can access external textures
   found in .tga files.

Parameters:

-  shaders (int): This param defines how many .cg shaders will be loaded.
   This value must be at least one.
   The path to these shaders will be found as a string in parameters
   shader0, shader1, ... shaderN, and so on.
   The path is relative to the directory the meta-shader
   was loaded from.

- filter_linearN (boolean): This parameter defines how the texture of the 
   input to pass N will be filtered.
   N = 0 affects how the pass 0 (initial pass) samples the raw input frame.
   N = 1 affects how pass 1 samples the raw input frame; in other words, it controls the sampling of pass 0 output
   (A boolean value here might be true/false/1/0).
   Should this value not be defined, the filtering option is
   implementation defined.

-  float_framebufferN (boolean): This parameters defines if shader N
   should render to a 32-bit floating point buffer.
   This only takes effect if shaderN is actually rendered to an FBO.
   This is useful for shaders which have to store FBO values outside [0, 1] range.

-  frame_count_modN (int): This positive parameter defines
   which modulo to apply to IN.frame_count.
   IN.frame_count will take the value frame_count % frame_count_modN.

-  scale_typeN (string): This can be set to one of these values:
   "source":   Output size of shader pass N is relative to the input size
               as found in IN.video_size. Value is float.
   "viewport": Output size of shader pass N is relative to the size of the
               window viewport. Value is float.
               This value can change over time if the user 
               resizes his/her window!
   "absolute": Output size is statically defined to a certain size.
               Useful for hi-res blenders or similiar.

   If no scale type is assumed, it is assumed that it is set to "source"
   with scaleN set to 1.0.

   It is possible to set scale_type_xN and scale_type_yN to specialize
   the scaling type in either direction. scale_typeN however
   overrides both of these.

   Exceptions:
   If no scale_type is set for the very last shader,
   it is assumed to output at the full resolution rather than assuming
   a scale of 1.0x, and bypasses any frame-buffer object rendering. 
   If there is only one shader, it is
   also considered to be the very last shader. If any scale option
   is defined, it has to go through a frame-buffer object, and
   subsequently rendered to screen. The filtering option used when stretching
   is implementation defined. It is encouraged to not have any
   scaling parameters in last pass if you care about the filtering
   option here.

   In first pass, should no scaling factor be defined, the implementation
   is free to choose a fitting scale. This means, that for a single pass
   shader, it is allowed for the implementation to set a scale, 
   render to FBO, and stretch. (Rule above).

-  scaleN, scale_xN, scale_yN (float/int):
   These values control the scaling params from scale_typeN.
   The values may be either floating or int depending on the type.
   scaleN controls both scaling type in horizontal and vertical directions.

   If scaleN is defined, scale_xN and scale_yN have no effect.
   scale_xN and scale_yN controls scaling properties for the directions
   separately. Should only one of these be defined, the other direction
   will assume a "source" scale with value 1.0, i.e. no change in resolution.

   Should scale_type_xN and scale_type_yN be set to different values,
   the use of scaleN is undefined (i.e. if X-type is absolute (takes int),
   and Y-type is source (takes float).)

-  textures (multiple strings):
   The textures param defines one or more lookup textures IDs.
   Several IDs are delimited with ';'. I.e. textures = "foo;bar"
   These IDs serves as the names for a Cg sampler uniform. I.e.
   uniform sampler2D foo;
   uniform sampler2D bar;

   The path of the textures can be found in the IDs, i.e.
   foo = image0.tga
   bar = image1.tga
   The paths of these textures are relative to the directory
   the meta-shader was loaded from.

   It is also possible to control the filtering options of the
   lookup texture as a boolean option in ID_linear = true/false.
   I.e. foo_linear = false, will force nearest neighbor filtering
   for texture "foo". If this param is not set, it is assumed to be
   linearily filtered.

   The textures will be loaded "as-is", 
   and coordinates (0, 0), (0, 1), (1, 0), (1, 1) will correspond
   to the corners of the texture. Since the texture coordinates
   of the texture in TEXUNIT0 might not be as convenient,
   the texture coordinates for all lookup textures will be found
   in TEXCOORD1. (Note: You cannot assume which texture unit the
   lookup textures will be bound to however!)

   The implementation only guarantees to be able to
   load plain top-left non-RLE .tga files. 
   It may provide possibilities to load i.e. .png and other popular formats.


Multi-pass uniforms:

   During multi-pass rendering, some additional uniforms are available.

   With multi-pass rendering, it is possible to utilize the resulting output
   for every pass that came before it, including the unfiltered input.
   This allows for an additive approach to shading rather than
   serial style.

   The unfiltered input can be found in the ORIG struct:

   uniform sampler2D ORIG.texture: Texture handle. 
   Must not be set to a predefined texture unit.
   uniform float2 ORIG.video_size: The video size of original frame.
   uniform float2 ORIG.texture_size: The texture size of original frame.
   in float2 ORIG.tex_coord: An attribute input holding the texture
                             coordinates of original frame.

   PASS%u: This struct holds the same data as the ORIG struct,
   although the result of passes {1, 2, 3 ...}, i.e.
   PASS1.texture holds the result of the first shader pass.
   If rendering pass N, passes {1, ..., N-2} are available.
   (N-1 being input in the regular IN structure).

   PREV: 
   This struct holds the same data as the ORIG struct,
   and corresponds to the raw input image from the previous frame.
   Useful for motion blur.

   PREV1..6:
   Similar struct as PREV, but holds the data for passes further back in time.
   PREV1 is the frame before PREV, PREV2 the frame before that again, and so on.
   This allows up to 8-tap motion blur.


For backend implementers:
===================================
 -- Rendering the shader chain: --
===================================

With all these options, the rendering pipeline can become somewhat complex.
The meta-shader format greatly utilizes the possibility of offscreen
rendering to achieve its effects. 
In OpenGL usually this is referred to as frame-buffer objects,
and in HLSL as render targets (?). This feature will be referred to as
FBO from here. FBO texture is assumed to be a texture bound to the FBO.

As long as the visual result is approximately identical,
the implementation does not have
to employ FBO.

With multiple passes our chain looks like this conceptually:

|Source image| ---> |Shader 0| ---> |FBO 0| ---> |Shader 1| ---> 
|FBO 1| ---> |Shader 2| ---> (Back buffer)

In the case that Shader 2 has set some scaling params, we need to first render
to an FBO before stretching it to the back buffer.

|Source image| ---> ... |Shader 2| ---> |FBO 2| ---> (Back buffer)

Scaling parameters determine the sizes of the FBOs. For visual fidelity it
is recommended that power-of-two sized textures are bound to them. This
is due to floating point inaccuracies that become far more apparent when not
using power-of-two textures. If the absolute maximum size of the source image
is known, then it is possible to preallocate the FBOs.

Do note that the size of FBOn is determined by dimensions of FBOn-1 
when "source" scale is used, _not_ the source image size! 
Of course, FBO0 would use source image size, as there is no FBO-1 ;)

I.e., with SNES there is a maximum width of 512 and height of 478.
If a source relative scale of 3.0x is desired for first pass, it is thus safe to
allocate a FBO with size of 2048x2048. However, most frames will just use a
tiny fraction of this texture.

With "viewport" scale it might be necessary to reallocate the FBO in run-time
if the user resizes the window.

More Repositories

1

RetroArch

Cross-platform, sophisticated frontend for the libretro API. Licensed GPLv3.
C
10,167
star
2

Lakka-LibreELEC

Lakka is a lightweight Linux distribution that transforms a small computer into a full blown game console.
Makefile
1,741
star
3

glsl-shaders

This repo is for glsl shaders converted by hand from libretro's common-shaders repo, since some don't play nicely with the cg2glsl script.
GLSL
824
star
4

libretro-database

Repository containing cheatcode files, content data files, etc.
Python
680
star
5

ludo

A libretro frontend written in golang
Go
590
star
6

libretro-super

Super repo for other libretro projects. Fetches, builds and installs.
Shell
401
star
7

libretro-thumbnails

Boxarts, titlescreen, and in-game screenshots for the no-intro DATs used by RetroArch
311
star
8

beetle-psx-libretro

Standalone port/fork of Mednafen PSX to the Libretro API.
C
307
star
9

parallel-n64

Optimized/rewritten Nintendo 64 emulator made specifically for Libretro. Originally based on Mupen64 Plus.
C++
272
star
10

retroarch-joypad-autoconfig

RetroArch joypad autoconfig files
Ruby
258
star
11

docs

This is a repo of the RetroArch official document page.
TeX
255
star
12

mame2003-plus-libretro

Updated 2018 version of MAME (0.78) for libretro. with added game support plus many fixes and improvements
C
188
star
13

retroarch-assets

Assets needed for RetroArch - e.g. menu drivers, etc. Also contains the official branding.
Shell
170
star
14

mupen64plus-libretro-nx

Improved mupen64plus libretro core reimplementation
C
169
star
15

LRPS2

C
168
star
16

libretro-lutro

An experimental lua game framework for libretro following the LÖVE API
C
133
star
17

libretro-common

Reusable coding blocks useful for libretro core and frontend development, written primarily in C. Permissively licensed.
C
122
star
18

swanstation

C++
122
star
19

libretro-uae

PUAE libretro
C
115
star
20

libretro-fceumm

FCEUmm libretro port.
C
107
star
21

snes9x2010

Snes9x 2010. Port of Snes9x 1.52+ to Libretro (previously called SNES9x Next). Rewritten in C and several optimizations and speedhacks.
C
95
star
22

common-overlays

Collection of overlay files for use with libretro frontends, such as RetroArch.
Shell
91
star
23

mame2003-libretro

MAME 0.78 for libretro. Compatible with MAME 0.78 sets.
C
90
star
24

gambatte-libretro

Hard fork of Gambatte to the libretro API.
C
87
star
25

nxengine-libretro

Port of NxEngine to the libretro API. NXEngine is a Cave Story game engine clone
C
81
star
26

vba-next

Optimized port of VBA-M to Libretro.
C
79
star
27

overlay-borders

A place for collecting decorative/cosmetic overlays for use with RetroArch.
67
star
28

libretro-prboom

Port of prboom to libretro - plays Doom, Doom II, Final Doom and other Doom IWAD mods.
C++
62
star
29

libretro-chailove

❤️ 2D Game Framework with ChaiScript
C++
61
star
30

neocd_libretro

Neo Geo CD emulator for libretro
C++
61
star
31

dosbox-libretro

Port of DOSBox (upstream) to the libretro API.
C++
57
star
32

libretro-samples

A set of samples to illustrate libretro API.
C
57
star
33

libretro-core-info

Mirror of libretro's core info files. Submit changes to libretro-super instead.
Makefile
57
star
34

blastem

Upstream tracking repo of BlastEm, the fast and accurate Genesis emulator, with libretro specific changes
C
51
star
35

opera-libretro

Port of 4DO/libfreedo to libretro.
C
48
star
36

arcade-overlays

Pawn
39
star
37

bsnes-mercury

Fork of bsnes with various performance improvements.
C++
39
star
38

blueMSX-libretro

Port of blueMSX to the libretro API.
C
39
star
39

nestopia

Nestopia emulator with libretro interface
C++
37
star
40

LudOS

Just enough OS for libretro using the Ludo frontend on a LibreELEC 9.2 base
Makefile
37
star
41

tyrquake

Libretro port of Tyrquake (Quake 1 engine)
C
36
star
42

fuse-libretro

A port of the Fuse Unix Spectrum Emulator to libretro
C
35
star
43

snes9x2002

Snes9x 2002. Port of SNES9x 1.39 for libretro (was previously called PocketSNES). Heavily optimized for ARM.
C
34
star
44

mame2000-libretro

2000 version of MAME (0.37b5) for libretro. Compatible with iMAME4All/MAME4Droid/MAME 0.37b5 sets.
C
34
star
45

desmume2015

Port of Desmume to libretro based on Desmume SVN circa 2015.
C++
30
star
46

mame2010-libretro

Late 2010 version of MAME (0.139) for libretro. Compatible with MAME 0.139 sets.
C
30
star
47

libretro.github.com

HTML
29
star
48

fbalpha2012

Final Burn Alpha 2012. Port of Final Burn Alpha to Libretro (0.2.97.24).
C++
29
star
49

gw-libretro

A libretro core for Game & Watch simulators
C
28
star
50

virtualjaguar-libretro

Hard fork of Virtual Jaguar (abandoned project) to Libretro
C
28
star
51

FreeIntv

A libretro emulation core for the Mattel Intellivision designed to be compatible with joypads from the SNES era forward
Assembly
26
star
52

mame2016-libretro

Late 2016 version of MAME (0.174) for libretro. Compatible with MAME 0.174 sets.
C++
26
star
53

fmsx-libretro

Port of fMSX to the libretro API.
C
25
star
54

shader-previews

A repo to store thumbnail previews for RetroArch's many shaders.
24
star
55

beetle-pce-fast-libretro

Standalone fork of Mednafen PCE Fast to libretro
C
24
star
56

tgbdual-libretro

libretro port of TGB Dual
C
23
star
57

hatari

New rebasing of Hatari based on Mercurial upstream. Tries to be a shallow fork for easy upstreaming later on.
C
23
star
58

vbam-libretro

A fork of VBA-M with libretro integration
C++
22
star
59

stella2014-libretro

Port of Stella to libretro.
C++
22
star
60

parallel-rsp

C
21
star
61

libretro-cap32

caprice32 4.2.0 libretro
C
21
star
62

PokeMini

Obscure nintendo handheld emulator
C
20
star
63

beetle-vb-libretro

Standalone hard fork of Mednafen VB to libretro.
C
19
star
64

beetle-pce-libretro

Standalone hard fork of Mednafen PCE to libretro
C
18
star
65

beetle-supergrafx-libretro

Standalone port of Mednafen PCE Fast to libretro. This one only emulates a SuperGrafx TG-16.
C
18
star
66

ecwolf

Libretro port of ECWolf
C++
18
star
67

81-libretro

A port of the EightyOne ZX81 Emulator to libretro
C
18
star
68

beetle-wswan-libretro

Standalone hard fork of Mednafen WonderSwan to libretro, itself a fork of Cygne
C
17
star
69

lutro-platformer

A platform game demo for libretro-lutro
Lua
16
star
70

Genesis-Plus-GX-Wide

Widescreen modification of Genesis Plus GX
C
16
star
71

mame2015-libretro

Late 2014/Early 2015 version of MAME (0.160-ish) for libretro. Compatible with MAME 0.160 sets.
C
16
star
72

libretro-2048

Port of 2048 puzzle game to the libretro API. http://gabrielecirulli.github.io/2048/
C
15
star
73

REminiscence

Flashback engine reimplementation
C++
15
star
74

libretro-mpv

mpv media player libretro core
C
15
star
75

pcsx_rearmed_switch

PCSX ReARMed specifically for Switch right now. Separate repo might go away later.
C
15
star
76

go-nanoarch

Minimal libretro frontend written in golang
C
14
star
77

retroarch-snap

RetroArch snap package
Shell
14
star
78

fceu-next

Port of FCEUmm / FCEUX to Libretro.
C
13
star
79

libretro-content

Content provided through the Content Downloader.
Makefile
13
star
80

prosystem-libretro

Port of ProSystem to the libretro API.
C
12
star
81

daphne

C
11
star
82

netplay-lobby-server-go

Netplay lobby server implemented in GO.
Go
11
star
83

arduous

C
11
star
84

libretro-handy

K. Wilkins' Atari Lynx emulator Handy (http://handy.sourceforge.net/) for libretro
C
11
star
85

libretro-gme

Port of blargg's Game_Music_Emu library
C
11
star
86

libretro-o2em

Port of O2EM to the libretro API, an Odyssey 2 / VideoPac emulator.
C
11
star
87

bsnes-libretro-cplusplus98

libretro implementation of the core emulation in BSNES, a Super Nintendo (SNES) emulator.
C++
11
star
88

pcsx1-libretro

PCSX1 rewritten for libretro only.
C
10
star
89

atv_menu

Android TV menu driver for RetroArch
C++
10
star
90

bsnes2014

Libretro fork of bsnes. As close to upstream as possible.
C++
9
star
91

bnes-libretro

libretro implementation of bNES
C++
9
star
92

desmume2014

Port of Desmume to libretro based on Desmume SVN circa 2015.
C++
9
star
93

fbalpha2012_neogeo

Final Burn Alpha 2012. Port of Final Burn Alpha to Libretro (0.2.97.24). Standalone core for Neo Geo.
C
9
star
94

minibrowser

C
8
star
95

beetle-ngp-libretro

Standalone port of Mednafen NGP to the libretro API, itself a fork of Neopop.
C
8
star
96

netplay-mitm-server

C++
8
star
97

smsplus-gx

Improved port of SMSPlus-GX by gameblabla for libretro
C
8
star
98

paraLLeXT

Rebased parallel build.
C
8
star
99

lutro-status

Compare Lutro's API to the LOVE API, written by @Feufochmar
Lua
8
star
100

libretro-directxbox

C
8
star