Skip to content
Themaister edited this page Apr 30, 2013 · 2 revisions

Purpose

Cg shaders is a spec from nVidia. It has the great advantage that shaders written in Cg are compatible with both OpenGL and Direct3D. It is also compatible with PlayStation 3 as well. They are also compatible with basic HLSL if some considerations are taken into account. They can even be automatically compiled into GLSL shaders, which makes Cg shaders a true "write once, run everywhere" shader format. We encourage new shaders targeting RetroArch to be written in this format.

Example Cg shader

void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,
   float2 tex : TEXCOORD,
   out float2 oTex : TEXCOORD
)
{
   oPosition = mul(modelViewProj, position);
   oTex = tex;
}

float4 main_fragment (float2 tex : TEXCOORD, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
   return tex2D(s0, tex);
}

Specification

The Cg shader spec used in RetroArch is documented here. It defines single-pass Cg shaders as well as multi-pass shaders using a custom Cg preset format (.cgp).

Example Cg preset

shaders = 2
shader0 = 4xBR-v3.9.cg
scale_type0 = source
scale0 = 4.0
filter_linear0 = false
shader1 = dummy.cg
filter_linear1 = true